Browse Source

Use xmalloc in splitstr

Update the splitstr module to abort in case of ENOMEM.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
5cd4e4e947
  1. 7
      lib/splitstr.c

7
lib/splitstr.c

@ -23,9 +23,7 @@
#include <splitstr.h>
#include <errno.h>
#ifdef EXIT_ON_ENOMEM
#include <xmem.h>
#endif
/*
* The following call
@ -76,12 +74,7 @@ splitstr(const char *str, char delim, size_t *ntoken)
is_token = 0;
}
#ifdef EXIT_ON_ENOMEM
index = xmalloc((n + 1) * sizeof(char *) + l + n);
#else
if ( ! (index = malloc((n + 1) * sizeof(char *) + l + n)) )
return NULL;
#endif
copy = (char *)(index + (n + 1));
/* Second parsing to copy the tokens in the buffer. */

Loading…
Cancel
Save