diff options
author | ash <alexander.naumochkin@gmail.com> | 2023-03-15 15:46:29 +0300 |
---|---|---|
committer | Gavin D. Howard <gavin@gavinhoward.com> | 2023-03-15 10:06:34 -0600 |
commit | 0c42c52dfc0735026cb6d2534dc24436ff19778f (patch) | |
tree | 489a6cd1a726f241a54a09cc373b3a4f85f164e7 | |
parent | 71fa3cd4029d416a5272b262736c4d6ab709b6ce (diff) | |
download | bc-0c42c52dfc0735026cb6d2534dc24436ff19778f.tar.gz |
Fix incorrect processing of env:BC_LINE_LENGTH=0
Casting int -1 to size_t produces SIZE_T_MAX so
BC_NUM_PRINT_WIDTH is used instead of 0
-rw-r--r-- | src/vm.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -622,8 +622,11 @@ bc_vm_envLen(const char* var) if (num) { // Parse it and clamp it if needed. - len = (size_t) atoi(lenv) - 1; - if (len == 1 || len >= UINT16_MAX) len = BC_NUM_PRINT_WIDTH; + len = (size_t) strtol(lenv, NULL, 10); + if (len) { + if (len < 3 || len > UINT16_MAX) len = BC_NUM_PRINT_WIDTH; + else len--; + } } // Set the default. else len = BC_NUM_PRINT_WIDTH; |