From 6af010f26d6f14c6a9f6a3af2e598f6540541fa7 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 28 Jan 2015 00:40:39 +0900 Subject: [PATCH] SIZE_MAX is not defined in ISO C89 --- extlib/benz/string.c | 24 ++++++++++++++---------- extlib/benz/vm.c | 4 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/extlib/benz/string.c b/extlib/benz/string.c index 57c063c5..da6614dd 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -368,17 +368,19 @@ pic_str_string_map(pic_state *pic) pic_get_args(pic, "l*", &proc, &argc, &argv); - len = SIZE_MAX; - for (i = 0; i < argc; ++i) { + if (argc == 0) { + pic_errorf(pic, "string-map: one or more strings expected, but got zero"); + } else { + pic_assert_type(pic, argv[0], str); + len = pic_strlen(pic_str_ptr(argv[0])); + } + for (i = 1; i < argc; ++i) { pic_assert_type(pic, argv[i], str); len = len < pic_strlen(pic_str_ptr(argv[i])) ? len : pic_strlen(pic_str_ptr(argv[i])); } - if (len == SIZE_MAX) { - pic_errorf(pic, "string-map: one or more strings expected, but got zero"); - } buf = pic_malloc(pic, len); pic_try { @@ -413,17 +415,19 @@ pic_str_string_for_each(pic_state *pic) pic_get_args(pic, "l*", &proc, &argc, &argv); - len = SIZE_MAX; - for (i = 0; i < argc; ++i) { + if (argc == 0) { + pic_errorf(pic, "string-map: one or more strings expected, but got zero"); + } else { + pic_assert_type(pic, argv[0], str); + len = pic_strlen(pic_str_ptr(argv[0])); + } + for (i = 1; i < argc; ++i) { pic_assert_type(pic, argv[i], str); len = len < pic_strlen(pic_str_ptr(argv[i])) ? len : pic_strlen(pic_str_ptr(argv[i])); } - if (len == SIZE_MAX) { - pic_errorf(pic, "string-map: one or more strings expected, but got zero"); - } for (i = 0; i < len; ++i) { vals = pic_nil_value(); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 23412278..682a873c 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -200,6 +200,7 @@ pic_get_args(pic_state *pic, const char *format, ...) if (i < argc) { pic_value v; int x; + size_t s; v = GET_OPERAND(pic, i); switch (pic_type(v)) { @@ -208,8 +209,9 @@ pic_get_args(pic_state *pic, const char *format, ...) if (x < 0) { pic_errorf(pic, "pic_get_args: expected non-negative int, but got ~s", v); } + s = (size_t)x; if (sizeof(unsigned) > sizeof(size_t)) { - if ((unsigned)x > (unsigned)SIZE_MAX) { + if (x != (int)s) { pic_errorf(pic, "pic_get_args: int unrepresentable with size_t ~s", v); } }