From c304852ff24bab0c13bb327336d28cd17cb995b8 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Fri, 26 Sep 2008 15:41:39 -1000 Subject: Use asprintf() rather than malloc() and sprintf(). Use asprintf() for conversion and abort on memory allocation failures. --- src/ipcalc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ipcalc.c') diff --git a/src/ipcalc.c b/src/ipcalc.c index fc81ba26..23a72207 100644 --- a/src/ipcalc.c +++ b/src/ipcalc.c @@ -306,11 +306,14 @@ int main(int argc, const char **argv) { else tmp++; } + tmp = NULL; for (; i>0; i--) { - tmp = malloc(strlen(ipStr) + 3); - sprintf(tmp,"%s.0",ipStr); - ipStr = tmp; + if (asprintf(&tmp, "%s.0", ipStr) == -1) { + fprintf(stderr, "Memory allocation failure line %d\n", __LINE__); + abort(); + } + ipStr = tmp; } } -- cgit v1.2.1