sabotage-linux / netbsd-curses

libcurses and dependencies taken from netbsd and brought into a portable shape (at least to musl or glibc)
Other
147 stars 14 forks source link

Fix incorrect snprintf overflow checks #40

Closed michaelforney closed 4 years ago

michaelforney commented 4 years ago

This equality check only works if the LHS is evaluated before the RHS, but this is not guaranteed by the standard.

We can fix this by checking that the snprintf return value is less than the maximum buffer length, which also avoids an unnecessary traversal of the string.