summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-09-09 21:09:48 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-09-09 21:09:48 +0000
commit0d11284c9e87e6abece74ecdd07a603292b03671 (patch)
treed0131ca2e68451f8044d66613bfb8b6b3908a126 /src
parent35155485bb3c31b06e3cea38773fb0c7379c8c72 (diff)
downloadcoreutils-0d11284c9e87e6abece74ecdd07a603292b03671.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/nl.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/nl.c b/src/nl.c
index c1cb03bb9..c133f2562 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);
}