aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2008-09-26 15:41:39 -1000
committerHarald Hoyer <harald@redhat.com>2009-05-04 16:05:05 +0200
commit7e7689a8c0300fd76fd97613d2c49d06444cfa72 (patch)
tree912efe1005d947985c00c830d5fd9dcbafec5562
parentfd554aee69b567c6c2a1233ed46e608c1d29f70f (diff)
downloadinitscripts-7e7689a8c0300fd76fd97613d2c49d06444cfa72.tar
initscripts-7e7689a8c0300fd76fd97613d2c49d06444cfa72.tar.gz
initscripts-7e7689a8c0300fd76fd97613d2c49d06444cfa72.tar.bz2
initscripts-7e7689a8c0300fd76fd97613d2c49d06444cfa72.tar.xz
initscripts-7e7689a8c0300fd76fd97613d2c49d06444cfa72.zip
Use asprintf() rather than malloc() and sprintf().
Use asprintf() for conversion and abort on memory allocation failures.
-rw-r--r--src/ipcalc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/ipcalc.c b/src/ipcalc.c
index 52e2f24f..648e153c 100644
--- a/src/ipcalc.c
+++ b/src/ipcalc.c
@@ -300,11 +300,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;
}
}