Skip to content

Commit

Permalink
Fix overflow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mentoc3000 authored and pataxis committed Feb 12, 2024
1 parent ea3892c commit a0c1e9c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions object-detection/app/object_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,16 @@ static bool parseLabels(char*** labelsPtr,
labelIdx++;
for (size_t i = 0; i < labelsFileSize; i++) {
if (labelsData[i] == '\n') {
// Register the string start in the list of labels.
labelArray[labelIdx] = labelsData + i + 1;
labelIdx++;
if (i < (labelsFileSize - 1)) {
// Register the string start in the list of labels.
labelArray[labelIdx] = labelsData + i + 1;
labelIdx++;
}
// Replace the newline char with string-ending NULL char.
labelsData[i] = '\0';
}
}

// If the very last byte in the labels file was a new-line we just
// replace that with a NULL-char. Refer previous for loop skipping looking
// for new-line at the end of file.
if (labelsData[labelsFileSize - 1] == '\n') {
labelsData[labelsFileSize - 1] = '\0';
}

// Make sure we always have a terminating NULL char after the label file
// contents.
labelsData[labelsFileSize] = '\0';
Expand Down

0 comments on commit a0c1e9c

Please sign in to comment.