[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 1/3] search: fix "grep -Fif /dev/null"
From: |
Paolo Bonzini |
Subject: |
[RFC PATCH 1/3] search: fix "grep -Fif /dev/null" |
Date: |
Sun, 15 Aug 2010 10:57:58 -0400 |
* bootstrap.conf: Include gnulib module minmax.
* src/searchutils.c (mbtolower): Handle *N == 0 case.
* src/system.h: Include minmax.h from gnulib.
---
bootstrap.conf | 1 +
src/searchutils.c | 11 ++++++-----
src/system.h | 1 +
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 1da6823..77870fe 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -54,6 +54,7 @@ mbrlen
mbrtowc
memchr
mempcpy
+minmax
obstack
open
progname
diff --git a/src/searchutils.c b/src/searchutils.c
index 1192485..6f4a5d9 100644
--- a/src/searchutils.c
+++ b/src/searchutils.c
@@ -68,15 +68,16 @@ mbtolower (const char *beg, size_t *n)
const char *end;
char *p;
- assert (0 < *n);
-
- if (*n > outalloc)
+ if (*n > outalloc || outalloc == 0)
{
- out = xrealloc (out, *n);
- outalloc = *n;
+ outalloc = MAX(1, *n);
+ out = xrealloc (out, outalloc);
}
+
/* appease clang-2.6 */
assert (out);
+ if (*n == 0)
+ return out;
memset (&is, 0, sizeof (is));
memset (&os, 0, sizeof (os));
diff --git a/src/system.h b/src/system.h
index ee85b22..a0d3c4a 100644
--- a/src/system.h
+++ b/src/system.h
@@ -23,6 +23,7 @@
#include "binary-io.h"
#include "configmake.h"
#include "dirname.h"
+#include "minmax.h"
#if O_BINARY
# define HAVE_DOS_FILE_CONTENTS 1
--
1.7.1