aboutsummaryrefslogtreecommitdiff
path: root/run.c
diff options
context:
space:
mode:
authorzoulasc <zoulasc@users.noreply.github.com>2019-12-08 14:41:27 -0500
committerArnold Robbins <arnold@skeeve.com>2019-12-08 21:41:27 +0200
commitff5d67610caab71d38625c3f1788547d00391337 (patch)
tree60417a0c7c4db42d184ad60fc41ec7fe82946342 /run.c
parent108224b4845d7ac622cdc3dcbe47b463e4253a4b (diff)
downloadone-true-awk-ff5d67610caab71d38625c3f1788547d00391337.tar.gz
Fix printf formats for integers (#57)
* 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. * Fix formats for 32 bit machines broken by previous commit. We use intmax_t to provide maximum range for both 32 and 64 bit machines.
Diffstat (limited to 'run.c')
-rw-r--r--run.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/run.c b/run.c
index 624a784..4069f59 100644
--- a/run.c
+++ b/run.c
@@ -898,7 +898,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
break;
case 'o': case 'x': case 'X': case 'u':
flag = *(s-1) == 'l' ? 'd' : 'u';
- *(t-1) = 'l';
+ *(t-1) = 'j';
*t = *s;
*++t = '\0';
break;
@@ -934,8 +934,8 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
case 'a':
case 'A':
case 'f': snprintf(p, BUFSZ(p), fmt, getfval(x)); break;
- case 'd': snprintf(p, BUFSZ(p), fmt, (long) getfval(x)); break;
- case 'u': snprintf(p, BUFSZ(p), fmt, (int) getfval(x)); break;
+ case 'd': snprintf(p, BUFSZ(p), fmt, (intmax_t) getfval(x)); break;
+ case 'u': snprintf(p, BUFSZ(p), fmt, (uintmax_t) getfval(x)); break;
case 's':
t = getsval(x);
n = strlen(t);