From 0d11284c9e87e6abece74ecdd07a603292b03671 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 9 Sep 2005 21:09:48 +0000 Subject: [PATCH] (proc_text): Store match length in regoff_t, not int. Assume that negative return values less than -2 represent regoff_t overflow. (build_type_arg): Check for size_t overflow. --- src/nl.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/nl.c b/src/nl.c index c1cb03b..c133f25 100644 --- a/src/nl.c +++ b/src/nl.c @@ -1,5 +1,5 @@ /* nl -- number lines of files - Copyright (C) 89, 92, 1995-2004 Free Software Foundation, Inc. + Copyright (C) 89, 92, 1995-2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -247,7 +247,7 @@ build_type_arg (char **typep, struct re_pattern_buffer *regexp) *typep = optarg++; optlen = strlen (optarg); regexp->allocated = optlen * 2; - regexp->buffer = xmalloc (regexp->allocated); + regexp->buffer = xnmalloc (optlen, 2); regexp->translate = NULL; regexp->fastmap = xmalloc (256); regexp->fastmap_accurate = 0; @@ -342,12 +342,20 @@ proc_text (void) fputs (print_no_line_fmt, stdout); break; case 'p': - if (re_search (current_regex, line_buf.buffer, line_buf.length - 1, - 0, line_buf.length - 1, (struct re_registers *) 0) < 0) - fputs (print_no_line_fmt, stdout); - else - print_lineno (); - break; + switch (re_search (current_regex, line_buf.buffer, line_buf.length - 1, + 0, line_buf.length - 1, (struct re_registers *) 0)) + { + case -2: + error (EXIT_FAILURE, errno, _("error in regular expression search")); + + case -1: + fputs (print_no_line_fmt, stdout); + break; + + default: + print_lineno (); + break; + } } fwrite (line_buf.buffer, sizeof (char), line_buf.length, stdout); } -- 2.7.4