if (buflen < needed)
{
+ char *new_buffer;
+
buflen = needed;
- if ((buffer = realloc (buffer, buflen)) == NULL)
+
+ new_buffer = (char *) realloc (buffer, buflen);
+ if (new_buffer == NULL)
return NULL;
+
+ buffer = new_buffer;
}
return __md5_crypt_r (key, salt, buffer, buflen);
/* Return the canonical absolute name of a given file inside chroot.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
char *
chroot_canon (const char *chroot, const char *name)
{
- char *rpath, *dest, *extra_buf = NULL, *rpath_root;
- const char *start, *end, *rpath_limit;
+ char *rpath;
+ char *dest;
+ char *extra_buf = NULL;
+ char *rpath_root;
+ const char *start;
+ const char *end;
+ const char *rpath_limit;
int num_links = 0;
size_t chroot_len = strlen (chroot);
if (dest + (end - start) >= rpath_limit)
{
ptrdiff_t dest_offset = dest - rpath;
+ char *new_rpath;
new_size = rpath_limit - rpath;
if (end - start + 1 > PATH_MAX)
new_size += end - start + 1;
else
new_size += PATH_MAX;
- rpath = realloc (rpath, new_size);
- rpath_limit = rpath + new_size;
- if (rpath == NULL)
+ new_rpath = (char *) realloc (rpath, new_size);
+ if (new_rpath == NULL)
return NULL;
+ rpath = new_rpath;
+ rpath_limit = rpath + new_size;
dest = rpath + dest_offset;
}
origin = NULL;
do
{
+ char *new_origin;
+
len += 128;
- origin = (char *) realloc (origin, len);
+ new_origin = (char *) realloc (origin, len);
+ if (new_origin == NULL)
+ /* We exit the loop. Note that result == NULL. */
+ break;
+ origin = new_origin;
}
- while (origin != NULL
- && (result = __getcwd (origin, len - realname_len)) == NULL
+ while ((result = __getcwd (origin, len - realname_len)) == NULL
&& errno == ERANGE);
if (result == NULL)
static int
process_fd (struct convtable *tbl, int fd, FILE *output)
{
- /* we have a problem with reading from a desriptor since we must not
+ /* We have a problem with reading from a descriptor since we must not
provide the iconv() function an incomplete character or shift
sequence at the end of the buffer. Since we have to deal with
arbitrary encodings we must read the whole text in a buffer and
while (1)
{
ssize_t n;
+ char *new_inbuf;
/* Increase the buffer. */
+ new_inbuf = (char *) realloc (inbuf, maxlen + 32768);
+ if (new_inbuf == NULL)
+ {
+ error (0, errno, _("unable to allocate buffer for input"));
+ return -1;
+ }
+ inbuf = new_inbuf;
maxlen += 32768;
- inbuf = realloc (inbuf, maxlen);
- if (inbuf == NULL)
- error (0, errno, _("unable to allocate buffer for input"));
inptr = inbuf + actlen;
do
while (1)
{
ssize_t n;
+ char *new_inbuf;
/* Increase the buffer. */
+ new_inbuf = (char *) realloc (inbuf, maxlen + 32768);
+ if (new_inbuf == NULL)
+ {
+ error (0, errno, _("unable to allocate buffer for input"));
+ return -1;
+ }
+ inbuf = new_inbuf;
maxlen += 32768;
- inbuf = realloc (inbuf, maxlen);
- if (inbuf == NULL)
- error (0, errno, _("unable to allocate buffer for input"));
inptr = inbuf + actlen;
do
-/* Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
needed = cur_len + len + 1;
if (needed > *n)
{
+ char *new_lineptr;
+
if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
- *n = needed;
- *lineptr = (char *) realloc (*lineptr, needed);
- if (*lineptr == NULL)
+ new_lineptr = (char *) realloc (*lineptr, needed);
+ if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
+ *lineptr = new_lineptr;
+ *n = needed;
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
}
else
{
+ struct era_entry *new_eras = eras;
+
if (num_eras != new_num_eras)
- eras = (struct era_entry *) realloc (eras,
- new_num_eras
- * sizeof (struct era_entry));
- if (eras == NULL)
+ new_eras =
+ (struct era_entry *) realloc (eras,
+ new_num_eras
+ * sizeof (struct era_entry));
+ if (new_eras == NULL)
{
+ free (eras);
num_eras = 0;
eras = NULL;
}
{
const char *ptr = _NL_CURRENT (LC_TIME, _NL_TIME_ERA_ENTRIES);
num_eras = new_num_eras;
+ eras = new_eras;
for (cnt = 0; cnt < num_eras; ++cnt)
{
/* Return the canonical absolute name of a given file.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
if (dest + (end - start) >= rpath_limit)
{
ptrdiff_t dest_offset = dest - rpath;
+ char *new_rpath;
if (resolved)
{
new_size += end - start + 1;
else
new_size += path_max;
- rpath = realloc (rpath, new_size);
+ new_rpath = (char *) realloc (rpath, new_size);
+ if (new_rpath == NULL)
+ goto error;
+ rpath = new_rpath;
rpath_limit = rpath + new_size;
- if (rpath == NULL)
- return NULL;
dest = rpath + dest_offset;
}
if (sock < _rpc_dtablesize ())
{
+ struct pollfd *new_svc_pollfd;
+
xports[sock] = xprt;
if (sock < FD_SETSIZE)
FD_SET (sock, &svc_fdset);
return;
}
- ++svc_max_pollfd;
- svc_pollfd = realloc (svc_pollfd,
- sizeof (struct pollfd) * svc_max_pollfd);
- if (svc_pollfd == NULL) /* Out of memory */
+ new_svc_pollfd = (struct pollfd *) realloc (svc_pollfd,
+ sizeof (struct pollfd)
+ * (svc_max_pollfd + 1));
+ if (new_svc_pollfd == NULL) /* Out of memory */
return;
+ svc_pollfd = new_svc_pollfd;
+ ++svc_max_pollfd;
svc_pollfd[svc_max_pollfd - 1].fd = sock;
svc_pollfd[svc_max_pollfd - 1].events = (POLLIN | POLLPRI |
: (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
{
int newcount = pglob->gl_pathc + pglob->gl_offs;
+ char **new_gl_pathv;
- pglob->gl_pathv
+ new_gl_pathv
= (char **) realloc (pglob->gl_pathv,
(newcount + 1 + 1) * sizeof (char *));
- if (pglob->gl_pathv == NULL)
- return GLOB_NOSPACE;
+ if (new_gl_pathv == NULL)
+ {
+ nospace:
+ free (pglob->gl_pathv);
+ pglob->gl_pathv = NULL;
+ pglob->gl_pathc = 0;
+ return GLOB_NOSPACE;
+ }
+ pglob->gl_pathv = new_gl_pathv;
#if defined HAVE_STRDUP || defined _LIBC
pglob->gl_pathv[newcount] = strdup (dirname);
#else
{
size_t len = strlen (dirname) + 1;
- char *dircopy = malloc (len);
+ char *dircopy = (char *) malloc (len);
if (dircopy != NULL)
pglob->gl_pathv[newcount] = memcpy (dircopy, dirname, len);
}
#endif
if (pglob->gl_pathv[newcount] == NULL)
- {
- free (pglob->gl_pathv);
- return GLOB_NOSPACE;
- }
+ goto nospace;
pglob->gl_pathv[++newcount] = NULL;
++pglob->gl_pathc;
pglob->gl_flags = flags;
/* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
But if we have not found any matching entry and the GLOB_NOCHECK
- flag was set we must return the list consisting of the disrectory
- names followed by the filename. */
+ flag was set we must return the input pattern itself. */
if (pglob->gl_pathc + pglob->gl_offs == oldcount)
{
/* No matches. */
if (flags & GLOB_NOCHECK)
{
int newcount = pglob->gl_pathc + pglob->gl_offs;
+ char **new_gl_pathv;
- pglob->gl_pathv
- = (char **) realloc (pglob->gl_pathv,
- (newcount + 2)
- * sizeof (char *));
- if (pglob->gl_pathv == NULL)
+ new_gl_pathv = (char **) realloc (pglob->gl_pathv,
+ (newcount + 2)
+ * sizeof (char *));
+ if (new_gl_pathv == NULL)
{
globfree (&dirs);
return GLOB_NOSPACE;
}
+ pglob->gl_pathv = new_gl_pathv;
pglob->gl_pathv[newcount] = __strdup (pattern);
if (pglob->gl_pathv[newcount] == NULL)
if (nfound != 0)
{
- pglob->gl_pathv
+ char **new_gl_pathv;
+
+ new_gl_pathv
= (char **) realloc (pglob->gl_pathv,
(pglob->gl_pathc + pglob->gl_offs + nfound + 1)
* sizeof (char *));
- if (pglob->gl_pathv == NULL)
+ if (new_gl_pathv == NULL)
goto memory_error;
+ pglob->gl_pathv = new_gl_pathv;
for (; names != NULL; names = names->next)
pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name;