From 44cdfa0c77d53e32a84b87e83c05f82e35278100 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 19 Aug 2017 21:05:55 +0200 Subject: [PATCH] Remove use of feof and ferror as it is not needed as the return of fgetc is sufficent. --- m-array.h | 6 +++--- m-bitset.h | 4 ++-- m-dict.h | 8 ++++---- m-list.h | 6 +++--- m-rbtree.h | 6 +++--- m-string.h | 4 ++-- m-tuple.h | 4 ++-- m-variant.h | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/m-array.h b/m-array.h index eb1af7d3..b2b0b7a6 100644 --- a/m-array.h +++ b/m-array.h @@ -681,7 +681,7 @@ ARRAYI_CONTRACT(array); \ assert (file != NULL); \ M_C(name,_clean)(array); \ - char c = fgetc(file); \ + int c = fgetc(file); \ if (c != '[') return false; \ c = fgetc(file); \ if (c == ']') return true; \ @@ -691,9 +691,9 @@ do { \ bool b = M_GET_IN_STR oplist (item, file); \ c = fgetc(file); \ - if (!b) { break; } \ + if (b == false || c == EOF) { break; } \ M_C(name, _push_back)(array, item); \ - } while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \ + } while (c == M_GET_SEPARATOR oplist); \ M_GET_CLEAR oplist (item); \ ARRAYI_CONTRACT(array); \ return c == ']'; \ diff --git a/m-bitset.h b/m-bitset.h index 81be0a86..628cb1da 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -510,7 +510,7 @@ bitset_in_str(bitset_t set, FILE *file) BITSETI_CONTRACT (set); assert(file != NULL); bitset_clean(set); - char c = fgetc(file); + int c = fgetc(file); if (c != '[') return false; c = fgetc(file); do { @@ -518,7 +518,7 @@ bitset_in_str(bitset_t set, FILE *file) const bool b = (c == '1'); bitset_push_back (set, b); c = fgetc(file); - } while (c != ']' && !feof(file) && !ferror(file)); + } while (c != ']' && c != EOF); BITSETI_CONTRACT (set); return c == ']'; } diff --git a/m-dict.h b/m-dict.h index cf803eb4..bf117b1d 100644 --- a/m-dict.h +++ b/m-dict.h @@ -503,7 +503,7 @@ assert (file != NULL); \ DICTI_CONTRACT(name, dict); \ M_C(name, _clean)(dict); \ - char c = fgetc(file); \ + int c = fgetc(file); \ if (c != '{') return false; \ c = fgetc(file); \ if (c == '}') return true; \ @@ -515,14 +515,14 @@ do { \ bool b = M_GET_IN_STR key_oplist (key, file); \ c = fgetc(file); \ - if (!b) { break; } \ + if (b == false || c == EOF) { break; } \ if (c != ':') { c = 0; break; } \ b = M_GET_IN_STR value_oplist (value, file); \ - if (!b) { c = 0; break; } \ + if (b == false) { c = 0; break; } \ M_C(name, _set_at)(dict, key \ M_IF(isSet)( , M_DEFERRED_COMMA value)); \ c = fgetc(file); \ - } while (c == ',' && !feof(file) && !ferror(file)); \ + } while (c == ','); \ M_GET_CLEAR key_oplist (key); \ M_GET_CLEAR value_oplist (value); \ return c == '}'; \ diff --git a/m-list.h b/m-list.h index 1a99029a..e8127ef3 100644 --- a/m-list.h +++ b/m-list.h @@ -525,7 +525,7 @@ { \ assert (file != NULL && list != NULL); \ M_C(name,_clean)(list); \ - char c = fgetc(file); \ + int c = fgetc(file); \ if (c != '[') return false; \ c = fgetc(file); \ if (c == ']') return true; \ @@ -535,9 +535,9 @@ do { \ bool b = M_GET_IN_STR oplist (item, file); \ c = fgetc(file); \ - if (!b) { break; } \ + if (b == false || c == EOF) { break; } \ M_C(name, _push_back)(list, item); \ - } while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \ + } while (c == M_GET_SEPARATOR oplist); \ M_GET_CLEAR oplist (item); \ M_C(name, _reverse)(list); \ return c == ']'; \ diff --git a/m-rbtree.h b/m-rbtree.h index aee719df..c4330992 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -947,7 +947,7 @@ typedef enum { RBTREEI_CONTRACT(rbtree); \ assert (file != NULL); \ M_C(name,_clean)(rbtree); \ - char c = fgetc(file); \ + int c = fgetc(file); \ if (c != '[') return false; \ c = fgetc(file); \ if (c == ']') return true; \ @@ -957,9 +957,9 @@ typedef enum { do { \ bool b = M_GET_IN_STR oplist (item, file); \ c = fgetc(file); \ - if (!b) break; \ + if (b == false || c == EOF) break; \ M_C(name, _push)(rbtree, item); \ - } while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \ + } while (c == M_GET_SEPARATOR oplist); \ M_GET_CLEAR oplist (item); \ return c == ']'; \ } \ diff --git a/m-string.h b/m-string.h index 3f308cf9..172f4f91 100644 --- a/m-string.h +++ b/m-string.h @@ -794,11 +794,11 @@ string_in_str(string_t v, FILE *f) { STRING_CONTRACT(v); M_ASSUME (f != NULL); - char c = fgetc(f); + int c = fgetc(f); if (c != '"') return false; string_clean(v); c = fgetc(f); - while (c != '"' && !feof(f) && !ferror(f)) { + while (c != '"' && c != EOF) { if (c == '\\') { c = getc(f); if (c != '"') string_push_back (v, '\\'); diff --git a/m-tuple.h b/m-tuple.h index f8bdcd75..053fb57c 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -230,7 +230,7 @@ static inline bool M_C(name, _in_str)(M_C(name,_t) el, FILE *f) { \ bool comma = false; \ assert (f != NULL && el != NULL); \ - char c = fgetc(f); \ + int c = fgetc(f); \ if (c != '(') return false; \ M_MAP(TUPLE_DEFINE_IN_STR_FUNC , __VA_ARGS__) \ c = fgetc(f); \ @@ -239,7 +239,7 @@ #define TUPLE_DEFINE_IN_STR_FUNC(a) \ if (comma) { \ c = fgetc (f); \ - if (c != ',' || feof(f) || ferror(f)) return false; \ + if (c != ',' || c == EOF) return false; \ } \ comma = true; \ if (TUPLE_GET_IN_STR a (el -> TUPLE_GET_FIELD a, f) == false) \ diff --git a/m-variant.h b/m-variant.h index e7d3832c..8e179623 100644 --- a/m-variant.h +++ b/m-variant.h @@ -364,9 +364,9 @@ char variantTypeBuf[400]; \ if (fgetc(f) != '@') return false; \ /* First read the name of the type */ \ - char c = fgetc(f); \ + int c = fgetc(f); \ unsigned int i = 0; \ - while (c != '@' && !feof(f) && !ferror(f) && i < sizeof(variantTypeBuf) - 1) { \ + while (c != '@' && c != EOF && i < sizeof(variantTypeBuf) - 1) { \ variantTypeBuf[i++] = c; \ c = fgetc(f); \ } \