summaryrefslogtreecommitdiffstats
path: root/src/kash/expand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kash/expand.c')
-rw-r--r--src/kash/expand.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/kash/expand.c b/src/kash/expand.c
index ff30455..1131865 100644
--- a/src/kash/expand.c
+++ b/src/kash/expand.c
@@ -1555,15 +1555,15 @@ STATIC char *
cvtnum(shinstance *psh, int num, char *buf)
{
char temp[32];
+ char *p = &temp[sizeof(temp) - 1];
int neg = num < 0;
- char *p = temp + 31;
-
- temp[31] = '\0';
+ if (neg)
+ num = -num;
+ *p = '\0';
do {
*--p = num % 10 + '0';
} while ((num /= 10) != 0);
-
if (neg)
*--p = '-';
@@ -1576,11 +1576,12 @@ STATIC char *
cvtnum64(shinstance *psh, KI64 num, char *buf)
{
char temp[32];
+ char *p = &temp[sizeof(temp) - 1];
int neg = num < 0;
- char *p = temp + 31;
-
- temp[31] = '\0';
+ if (neg)
+ num = -num;
+ *p = '\0';
do {
*--p = num % 10 + '0';
} while ((num /= 10) != 0);