Skip to content

Bug std::string::NullStringBase does not work within a section. #499

@bwrsandman

Description

@bwrsandman

I'm hitting a limitation of NullString and by extension std::mem::read_unsigned when parsing data in a section.

The issue is when a NullString is encoded, it will try to measure the length based on the $ offset but using std::mem::read_unsigned but this function does not read in the current section.

DataType data[while(std::mem::read_unsigned($, sizeof(DataType)) != 0x00)];

Expected outcome: NullString's detected length should be based on the data in the current section
Actual outcome: NullString uses the offset in the main data to compute the length of string in a section.

hello.x.zip

Data:

00000000  57 68 6f 6f 70 73 21 00  00 00 00 00 00 00 00 00  |Whoops!.........|
00000010  48 65 6c 6c 6f 20 57 6f  72 6c 64 21 21 21 21 00  |Hello World!!!!.|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030

Pattern:

import std.mem;
import std.string;

std::mem::Section section = std::mem::create_section("MySection");
std::mem::copy_section_to_section(null, 0x10, section, 0, 0x20);
 
std::string::NullString nullstr @ 0x00 in section;
std::print("nullstr: {}", nullstr); // Expected "Hello World!", Actual "Hello W" which is the length of "Whoops"
char chararray[0x10] @ 0x00 in section;
std::print("chararr: {}", chararray); // Prints "Hello World!"

struct InSection {
    std::print("{}", $); // Prints 15
};
InSection a @ 15 in section;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions