@@ -108,7 +108,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
check_stdin();
case oldaskconfig:
fflush(stdout);
- fgets(line, 128, stdin);
+ xfgets(line, 128, stdin);
return 1;
default:
break;
@@ -306,7 +306,7 @@ static int conf_choice(struct menu *menu)
check_stdin();
case oldaskconfig:
fflush(stdout);
- fgets(line, 128, stdin);
+ xfgets(line, 128, stdin);
strip(line);
if (line[0] == '?') {
print_help(menu);
@@ -412,7 +412,7 @@ static void conf_write_string(bool headerfile, const char *name,
while (1) {
l = strcspn(str, "\"\\");
if (l) {
- fwrite(str, l, 1, out);
+ xfwrite(str, l, 1, out);
str += l;
}
if (!*str)
@@ -1087,7 +1087,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
{
- fwrite(str, strlen(str), 1, data);
+ xfwrite(str, strlen(str), 1, data);
}
void expr_fprint(struct expr *e, FILE *out)
@@ -169,6 +169,30 @@ static inline bool sym_has_value(struct symbol *sym)
return sym->flags & SYMBOL_DEF_USER ? true : false;
}
+#define internal_error(fmt, args...) \
+do { \
+ fprintf(stderr, "%s:%s:%i: %s: " fmt "\n", __FILE__, \
+ __func__, __LINE__, _("internal error"), ## args); \
+ exit(1); \
+} while (0)
+
+#define xfwrite(ptr, size, nmemb, stream) \
+({ \
+ size_t _nmemb = (nmemb); \
+ size_t ret = fwrite(ptr, size, _nmemb, stream); \
+ if (ret != _nmemb) \
+ internal_error("%s", _("fwrite() came up short")); \
+ ret; \
+})
+
+#define xfgets(s, size, stream) \
+({ \
+ char *ret = fgets(s, size, stream); \
+ if (ret == NULL) \
+ internal_error("%s", _("fgets() came up short")); \
+ ret; \
+})
+
#ifdef __cplusplus
}
#endif