aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2008-09-26 15:41:39 -1000
committerBill Nottingham <notting@redhat.com>2009-03-19 15:50:06 -0400
commitc304852ff24bab0c13bb327336d28cd17cb995b8 (patch)
tree4cb13c6473b7eeb571a4f19b69ea6139666eda87
parent17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40 (diff)
downloadinitscripts-c304852ff24bab0c13bb327336d28cd17cb995b8.tar
initscripts-c304852ff24bab0c13bb327336d28cd17cb995b8.tar.gz
initscripts-c304852ff24bab0c13bb327336d28cd17cb995b8.tar.bz2
initscripts-c304852ff24bab0c13bb327336d28cd17cb995b8.tar.xz
initscripts-c304852ff24bab0c13bb327336d28cd17cb995b8.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 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;
}
}