nl: fix integer-overflow bug

Problem reported by Roland Illig (Bug#37585)
* src/nl.c (print_lineno): Don’t rely on undefined behavior when
checking for integer overflow.
This commit is contained in:
Paul Eggert committed 2019-10-03 12:41:51 -07:00
1 parent bb23a7563f
commit ac2b4a43e6
1 file changed
+1 -5
+1 -5
View File
@@ -275,14 +275,10 @@ build_type_arg (char const **typep,
static void
print_lineno (void)
{
intmax_t next_line_no;
printf (lineno_format, lineno_width, line_no, separator_str);
next_line_no = line_no + page_incr;
if (next_line_no < line_no)
if (INT_ADD_WRAPV (line_no, page_incr, &line_no))
die (EXIT_FAILURE, 0, _("line number overflow"));
line_no = next_line_no;
}
/* Switch to a header section. */