Introduce a new add_off_t static function that exits with an error message if there's an overflow, otherwise returns their sum. Use this when adding values obtained from the input patch.
Details
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 ↗ | (On Diff #20356) | Is this variant of the code so much better than explicit overflow checks below that it warrants coding the same check twice ? You need to do the explicit check anyway, so why bother ? What can be done, instead, is to add e.g. sys/cdefs.h macro ADD_OF_CHECKED(a,b,result) and make this functionality generally useful, to avoid open-coding the same fragment several times. typeof() macro or generic C11 facility would allow to make that type-neutral. |
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 ↗ | (On Diff #20356) | Or may be sys/param.h is better place. |
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
78 ↗ | (On Diff #20356) | We could do away with the bzctrllen > OFF_MAX - HEADER_SIZE, bzctrllen + HEADER_SIZE > OFF_MAX - bzdatalen and bzctrllen + HEADER_SIZE > OFF_MAX - bzdatalen checks if we were so inclined. This approach is harder to get wrong (by missing an explicit overflow check), and is resilient to future changes in variable types. |
Looks good to me in principal.
usr.bin/bsdiff/bspatch/bspatch.c | ||
---|---|---|
70 ↗ | (On Diff #20356) | Maybe inline? |