mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use vec.data() instead of &vec[0]
In general `vec.data()` is always safe, whereas `&vec[0]` may fail when `vec` is empty.
This commit is contained in:
@@ -233,7 +233,7 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, std
|
||||
fileName, sectName.c_str(), i);
|
||||
|
||||
patch->rpnExpression.resize(rpnSize);
|
||||
size_t nbElementsRead = fread(&patch->rpnExpression[0], 1, rpnSize, file);
|
||||
size_t nbElementsRead = fread(patch->rpnExpression.data(), 1, rpnSize, file);
|
||||
|
||||
if (nbElementsRead != rpnSize)
|
||||
errx("%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
@@ -306,7 +306,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
if (sect_HasData(section->type)) {
|
||||
if (section->size) {
|
||||
section->data.resize(section->size);
|
||||
if (size_t nbRead = fread(§ion->data[0], 1, section->size, file);
|
||||
if (size_t nbRead = fread(section->data.data(), 1, section->size, file);
|
||||
nbRead != section->size)
|
||||
errx("%s: Cannot read \"%s\"'s data: %s", fileName, section->name.c_str(),
|
||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||
|
||||
Reference in New Issue
Block a user