diff options
author | zoulasc <zoulasc@users.noreply.github.com> | 2019-10-25 10:59:10 -0400 |
---|---|---|
committer | Arnold Robbins <arnold@skeeve.com> | 2019-10-25 10:59:09 -0400 |
commit | 0d8778bbbb415810bfd126694a38b6bf4b71e79c (patch) | |
tree | 9975240f57a5bf1ce0f36093b28ae04e8524419b /lib.c | |
parent | 1d6ddfd9c0ed7119c0601474cded3a385068e886 (diff) | |
download | one-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.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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); |