Skip to content

Commit

Permalink
Remove redundant scope and use proper return type in demo (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Dec 26, 2023
1 parent 5196754 commit 082d2ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ int main(int argc, char *argv[]) {

// Parse EXIF
easyexif::EXIFInfo result;
int code = result.parseFrom(buf, fsize);
easyexif::ParseError code = result.parseFrom(buf, fsize);
delete[] buf;
if (code != easyexif::ParseError::None) {
printf("Error parsing EXIF: code %d\n", code);
printf("Error parsing EXIF: code %d\n", static_cast<int>(code));
return -3;
}

Expand Down
28 changes: 14 additions & 14 deletions exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ easyexif::ParseError easyexif::EXIFInfo::parseFrom(const unsigned char *buf,
unsigned len) {
// Sanity check: all JPEG files start with 0xFFD8.
if (!buf || len < 4) {
return easyexif::ParseError::NoJPEG;
return ParseError::NoJPEG;
}

if (buf[0] != 0xFF || buf[1] != 0xD8) {
return easyexif::ParseError::NoJPEG;
return ParseError::NoJPEG;
}

// Sanity check: some cameras pad the JPEG image with some bytes at the end.
Expand All @@ -479,7 +479,7 @@ easyexif::ParseError easyexif::EXIFInfo::parseFrom(const unsigned char *buf,
}

if (len <= 2) {
return easyexif::ParseError::NoJPEG;
return ParseError::NoJPEG;
}

clear();
Expand All @@ -504,14 +504,14 @@ easyexif::ParseError easyexif::EXIFInfo::parseFrom(const unsigned char *buf,
}

if (offs + 4 > len) {
return easyexif::ParseError::NoEXIF;
return ParseError::NoEXIF;
}

offs += 2;

unsigned short section_length = parse_value<uint16_t>(buf + offs, false);
if (offs + section_length > len || section_length < 16) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

offs += 2;
Expand All @@ -535,11 +535,11 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
bool alignIntel = true; // byte alignment (defined in EXIF header)
unsigned offs = 0; // current offset into buffer
if (!buf || len < 6) {
return easyexif::ParseError::NoEXIF;
return ParseError::NoEXIF;
}

if (!std::equal(buf, buf + 6, "Exif\0\0")) {
return easyexif::ParseError::NoEXIF;
return ParseError::NoEXIF;
}
offs += 6;

Expand All @@ -555,7 +555,7 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
// -----------------------------
// 8 bytes
if (offs + 8 > len) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

unsigned tiff_header_start = offs;
Expand All @@ -566,15 +566,15 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
if (buf[offs] == 'M' && buf[offs + 1] == 'M') {
alignIntel = false;
} else {
return easyexif::ParseError::UnknownByteAlign;
return ParseError::UnknownByteAlign;
}
}

ByteAlign = alignIntel;
offs += 2;

if (0x2a != parse_value<uint16_t>(buf + offs, alignIntel)) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

offs += 2;
Expand All @@ -583,7 +583,7 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(

offs += first_ifd_offset - 4;
if (offs >= len) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

// Now parsing the first Image File Directory (IFD0, for the main image).
Expand All @@ -593,12 +593,12 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
// to the next IFD, which means this IFD must contain exactly 6 + 12 * num
// bytes of data.
if (offs + 2 > len) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

int num_entries = parse_value<uint16_t>(buf + offs, alignIntel);
if (offs + 6 + 12 * num_entries > len) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

offs += 2;
Expand Down Expand Up @@ -711,7 +711,7 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(

int num_sub_entries = parse_value<uint16_t>(buf + offs, alignIntel);
if (offs + 6 + 12 * num_sub_entries > len) {
return easyexif::ParseError::DataCorrupt;
return ParseError::DataCorrupt;
}

offs += 2;
Expand Down

0 comments on commit 082d2ba

Please sign in to comment.