malloc and realloc could return NULL when no memory is available.
The code doesn't handle errors, so use xmalloc/xrealloc instead.
While at it, sync alloclen's type with len's type, so both are ssize_t.
{
int ch;
int retval = 0, i;
- int alloclen = 128;
+ ssize_t alloclen = 128;
char *pathbuf;
static const struct option longopts[] = {
if (argc == 0)
usage(stderr);
- pathbuf = malloc(alloclen);
+ pathbuf = xmalloc(alloclen);
for (i = 0; i < argc; i++) {
char *s;
*/
while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
alloclen *= 2;
- pathbuf = realloc(pathbuf, alloclen);
+ pathbuf = xrealloc(pathbuf, alloclen);
}
free(buf);