1
1

tweaks: use a string-copy function that checks for out-of-memory

Этот коммит содержится в:
Benno Schulenberg 2019-10-13 12:38:46 +02:00
родитель d256d0cbc0
Коммит 06bbc70d4a
3 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -2303,7 +2303,7 @@ char *real_dir_from_tilde(const char *path)
if (userdata != NULL) if (userdata != NULL)
tilded = mallocstrcpy(tilded, userdata->pw_dir); tilded = mallocstrcpy(tilded, userdata->pw_dir);
#else #else
tilded = strdup(""); tilded = copy_of("");
#endif #endif
} }

Просмотреть файл

@ -103,7 +103,7 @@ void do_help(void)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
char *was_syntax = syntaxstr; char *was_syntax = syntaxstr;
#endif #endif
char *saved_answer = (answer != NULL) ? strdup(answer) : NULL; char *saved_answer = (answer != NULL) ? copy_of(answer) : NULL;
/* The current answer when the user invokes help at the prompt. */ /* The current answer when the user invokes help at the prompt. */
unsigned stash[sizeof(flags) / sizeof(flags[0])]; unsigned stash[sizeof(flags) / sizeof(flags[0])];
/* A storage place for the current flag settings. */ /* A storage place for the current flag settings. */

Просмотреть файл

@ -175,7 +175,7 @@ void jot_error(const char *msg, ...)
errors_tail = error; errors_tail = error;
if (rcfile_with_errors == NULL) if (rcfile_with_errors == NULL)
rcfile_with_errors = strdup(nanorc); rcfile_with_errors = copy_of(nanorc);
if (lineno > 0) if (lineno > 0)
length = snprintf(textbuf, MAXSIZE, _("Error in %s on line %zu: "), length = snprintf(textbuf, MAXSIZE, _("Error in %s on line %zu: "),
@ -326,7 +326,7 @@ void begin_new_syntax(char *ptr)
/* Initialize a new syntax struct. */ /* Initialize a new syntax struct. */
live_syntax = (syntaxtype *)nmalloc(sizeof(syntaxtype)); live_syntax = (syntaxtype *)nmalloc(sizeof(syntaxtype));
live_syntax->name = copy_of(nameptr); live_syntax->name = copy_of(nameptr);
live_syntax->filename = strdup(nanorc); live_syntax->filename = copy_of(nanorc);
live_syntax->lineno = lineno; live_syntax->lineno = lineno;
live_syntax->augmentations = NULL; live_syntax->augmentations = NULL;
live_syntax->extensions = NULL; live_syntax->extensions = NULL;
@ -1050,8 +1050,8 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
continue; continue;
} }
argument = strdup(ptr);
keyword = ptr; keyword = ptr;
argument = copy_of(ptr);
ptr = parse_next_word(ptr); ptr = parse_next_word(ptr);
/* File-matching commands need to be processed immediately; /* File-matching commands need to be processed immediately;
@ -1064,7 +1064,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
} else { } else {
newitem = nmalloc(sizeof(augmentstruct));; newitem = nmalloc(sizeof(augmentstruct));;
newitem->filename = strdup(nanorc); newitem->filename = copy_of(nanorc);
newitem->lineno = lineno; newitem->lineno = lineno;
newitem->data = argument; newitem->data = argument;
newitem->next = NULL; newitem->next = NULL;