diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-05-25 15:47:03 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-05-25 15:47:03 -0400 |
| commit | f148d861cb69419378d9e3ca4d9816f98e0a1cff (patch) | |
| tree | 6d595e75ef4cde36f25c556768388d337aa64e8b /src/stdlib | |
| parent | 145ccdea8ce8aa89448ea9302908b4dbc23d892f (diff) | |
Bugfix for converting negative integers to text
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/integers.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/stdlib/integers.c b/src/stdlib/integers.c index 7250e2a2..7c623663 100644 --- a/src/stdlib/integers.c +++ b/src/stdlib/integers.c @@ -28,9 +28,13 @@ public int Int$print(FILE *f, Int_t i) { static inline Text_t _int64_to_text(int64_t n) { + if (n == INT64_MIN) + return Text("-9223372036854775808"); + char buf[21] = {[20]=0}; // Big enough for INT64_MIN + '\0' char *p = &buf[19]; bool negative = n < 0; + if (negative) n = -n; // Safe to do because we checked for INT64_MIN earlier do { *(p--) = '0' + (n % 10); |
