]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(proc_text): Store match length in regoff_t,
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 9 Sep 2005 21:09:48 +0000 (21:09 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 9 Sep 2005 21:09:48 +0000 (21:09 +0000)
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

index c1cb03bb9cb064ad6998c8e68ff0050c76b42925..c133f2562fc29fcc907bb96d869e00b76f9607bd 100644 (file)
--- 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);
 }