Commit 8b28de13 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: don't call a thing malloc... when it doesn't call malloc()

No related merge requests found
Showing with 7 additions and 9 deletions
+7 -9
...@@ -65,7 +65,7 @@ char *do_browser(char *path) ...@@ -65,7 +65,7 @@ char *do_browser(char *path)
read_directory_contents: read_directory_contents:
/* We come here when we refresh or select a new directory. */ /* We come here when we refresh or select a new directory. */
path = mallocstrassn(path, get_full_path(path)); path = free_and_assign(path, get_full_path(path));
if (path != NULL) if (path != NULL)
dir = opendir(path); dir = opendir(path);
...@@ -243,7 +243,7 @@ char *do_browser(char *path) ...@@ -243,7 +243,7 @@ char *do_browser(char *path)
sunder(answer); sunder(answer);
align(&answer); align(&answer);
path = mallocstrassn(path, real_dir_from_tilde(answer)); path = free_and_assign(path, real_dir_from_tilde(answer));
/* If the given path is relative, join it with the current path. */ /* If the given path is relative, join it with the current path. */
if (*path != '/') { if (*path != '/') {
...@@ -367,7 +367,7 @@ char *do_browse_from(const char *inpath) ...@@ -367,7 +367,7 @@ char *do_browse_from(const char *inpath)
* at all. If so, we'll just pass the current directory to * at all. If so, we'll just pass the current directory to
* do_browser(). */ * do_browser(). */
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
path = mallocstrassn(path, striponedir(path)); path = free_and_assign(path, striponedir(path));
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
char * currentdir = charalloc(PATH_MAX + 1); char * currentdir = charalloc(PATH_MAX + 1);
......
...@@ -1226,7 +1226,7 @@ void do_insertfile( ...@@ -1226,7 +1226,7 @@ void do_insertfile(
{ {
/* Make sure the path to the file specified in answer is /* Make sure the path to the file specified in answer is
* tilde-expanded. */ * tilde-expanded. */
answer = mallocstrassn(answer, real_dir_from_tilde(answer)); answer = free_and_assign(answer, real_dir_from_tilde(answer));
/* Save the file specified in answer in the current buffer. */ /* Save the file specified in answer in the current buffer. */
open_buffer(answer, TRUE); open_buffer(answer, TRUE);
......
...@@ -728,7 +728,7 @@ void *nmalloc(size_t howmuch); ...@@ -728,7 +728,7 @@ void *nmalloc(size_t howmuch);
void *nrealloc(void *ptr, size_t howmuch); void *nrealloc(void *ptr, size_t howmuch);
char *mallocstrncpy(char *dest, const char *src, size_t n); char *mallocstrncpy(char *dest, const char *src, size_t n);
char *mallocstrcpy(char *dest, const char *src); char *mallocstrcpy(char *dest, const char *src);
char *mallocstrassn(char *dest, char *src); char *free_and_assign(char *dest, char *src);
size_t get_page_start(size_t column); size_t get_page_start(size_t column);
size_t xplustabs(void); size_t xplustabs(void);
size_t actual_x(const char *s, size_t column); size_t actual_x(const char *s, size_t column);
......
...@@ -427,10 +427,8 @@ char *mallocstrcpy(char *dest, const char *src) ...@@ -427,10 +427,8 @@ char *mallocstrcpy(char *dest, const char *src)
return mallocstrncpy(dest, src, (src == NULL) ? 1 : strlen(src) + 1); return mallocstrncpy(dest, src, (src == NULL) ? 1 : strlen(src) + 1);
} }
/* Free the malloc()ed string at dest and return the malloc()ed string /* Free the string at dest and return the string at src. */
* at src. Should be used as: "answer = mallocstrassn(answer, char *free_and_assign(char *dest, char *src)
* real_dir_from_tilde(answer));". */
char *mallocstrassn(char *dest, char *src)
{ {
free(dest); free(dest);
return src; return src;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment