aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorash <alexander.naumochkin@gmail.com>2023-03-15 15:46:29 +0300
committerGavin D. Howard <gavin@gavinhoward.com>2023-03-15 10:06:34 -0600
commit0c42c52dfc0735026cb6d2534dc24436ff19778f (patch)
tree489a6cd1a726f241a54a09cc373b3a4f85f164e7
parent71fa3cd4029d416a5272b262736c4d6ab709b6ce (diff)
downloadbc-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.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/vm.c b/src/vm.c
index 29c2715d..ed7d8d4f 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -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;