SIZE_MAX is not defined in ISO C89

This commit is contained in:
Yuichi Nishiwaki 2015-01-28 00:40:39 +09:00
parent 32d6760d4f
commit 6af010f26d
2 changed files with 17 additions and 11 deletions

View File

@ -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();

View File

@ -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);
}
}