aboutsummaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorzoulasc <zoulasc@users.noreply.github.com>2019-10-25 10:59:10 -0400
committerArnold Robbins <arnold@skeeve.com>2019-10-25 10:59:09 -0400
commit0d8778bbbb415810bfd126694a38b6bf4b71e79c (patch)
tree9975240f57a5bf1ce0f36093b28ae04e8524419b /lib.c
parent1d6ddfd9c0ed7119c0601474cded3a385068e886 (diff)
downloadone-true-awk-0d8778bbbb415810bfd126694a38b6bf4b71e79c.tar.gz
more cleanups (#55)
* More cleanups: - sprinkle const - add a macro (setptr) that cheats const to temporarily NUL terminate strings remove casts from allocations - use strdup instead of strlen+strcpy - use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x))) - add -Wcast-qual (and casts through unitptr_t in the two macros we cheat (xfree, setptr)). * More cleanups: - add const - use bounded sscanf - use snprintf instead of sprintf * More cleanup: - use snprintf/strlcat instead of sprintf/strcat - use %j instead of %l since we are casting to intmax_t/uintmax_t * Merge the 3 copies of the code that evaluated array strings with separators and convert them to keep track of lengths and use memcpy instead of strcat.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 0ab56be..b4a0d89 100644
--- a/lib.c
+++ b/lib.c
@@ -79,7 +79,7 @@ void makefields(int n1, int n2) /* create $n1..$n2 inclusive */
if (fldtab[i] == NULL)
FATAL("out of space in makefields %d", i);
*fldtab[i] = dollar1;
- sprintf(temp, "%d", i);
+ snprintf(temp, sizeof(temp), "%d", i);
fldtab[i]->nval = tostring(temp);
}
}
@@ -259,7 +259,7 @@ char *getargv(int n) /* get ARGV[n] */
char *s, temp[50];
extern Array *ARGVtab;
- sprintf(temp, "%d", n);
+ snprintf(temp, sizeof(temp), "%d", n);
if (lookup(temp, ARGVtab) == NULL)
return NULL;
x = setsymtab(temp, "", 0.0, STR, ARGVtab);