summaryrefslogtreecommitdiff
path: root/lib/striconveh.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2008-03-30 18:48:14 +0200
committerBruno Haible <bruno@clisp.org>2008-03-30 18:48:14 +0200
commit53ddc721f3a7aa950d6503f51bfcb4314612d9b9 (patch)
tree3c50f86308b18af50afbb4df875550b52b50897b /lib/striconveh.c
parenta4ce14d54b63bdca11f707e322100dfaaa117943 (diff)
downloadgnulib-53ddc721f3a7aa950d6503f51bfcb4314612d9b9.tar.gz
Avoid failure when attempting to return empty iconv results on some platforms.
Diffstat (limited to 'lib/striconveh.c')
-rw-r--r--lib/striconveh.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/striconveh.c b/lib/striconveh.c
index 99bbe18d29..761f3b115b 100644
--- a/lib/striconveh.c
+++ b/lib/striconveh.c
@@ -1,5 +1,5 @@
/* Character set conversion with error handling.
- Copyright (C) 2001-2007 Free Software Foundation, Inc.
+ Copyright (C) 2001-2008 Free Software Foundation, Inc.
Written by Bruno Haible and Simon Josefsson.
This program is free software: you can redistribute it and/or modify
@@ -870,9 +870,10 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
/* Now the final memory allocation. */
if (result == tmpbuf)
{
+ size_t memsize = length + extra_alloc;
char *memory;
- memory = (char *) malloc (length + extra_alloc);
+ memory = (char *) malloc (memsize > 0 ? memsize : 1);
if (memory != NULL)
{
memcpy (memory, tmpbuf, length);
@@ -887,9 +888,10 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
else if (result != *resultp && length + extra_alloc < allocated)
{
/* Shrink the allocated memory if possible. */
+ size_t memsize = length + extra_alloc;
char *memory;
- memory = (char *) realloc (result, length + extra_alloc);
+ memory = (char *) realloc (result, memsize > 0 ? memsize : 1);
if (memory != NULL)
result = memory;
}