commit 8b28de13139bdab2b5d83bb93865d6c2230e1395
parent 8fa72fb7e774144b01447d57bec8aa710442d906
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 13 Jul 2016 15:04:40 +0200
tweaks: don't call a thing malloc... when it doesn't call malloc()
Diffstat:
4 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -65,7 +65,7 @@ char *do_browser(char *path)
read_directory_contents:
/* 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)
dir = opendir(path);
@@ -243,7 +243,7 @@ char *do_browser(char *path)
sunder(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 (*path != '/') {
@@ -367,7 +367,7 @@ char *do_browse_from(const char *inpath)
* at all. If so, we'll just pass the current directory to
* do_browser(). */
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)) {
char * currentdir = charalloc(PATH_MAX + 1);
diff --git a/src/files.c b/src/files.c
@@ -1226,7 +1226,7 @@ void do_insertfile(
{
/* Make sure the path to the file specified in answer is
* 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. */
open_buffer(answer, TRUE);
diff --git a/src/proto.h b/src/proto.h
@@ -728,7 +728,7 @@ void *nmalloc(size_t howmuch);
void *nrealloc(void *ptr, size_t howmuch);
char *mallocstrncpy(char *dest, const char *src, size_t n);
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 xplustabs(void);
size_t actual_x(const char *s, size_t column);
diff --git a/src/utils.c b/src/utils.c
@@ -427,10 +427,8 @@ char *mallocstrcpy(char *dest, const char *src)
return mallocstrncpy(dest, src, (src == NULL) ? 1 : strlen(src) + 1);
}
-/* Free the malloc()ed string at dest and return the malloc()ed string
- * at src. Should be used as: "answer = mallocstrassn(answer,
- * real_dir_from_tilde(answer));". */
-char *mallocstrassn(char *dest, char *src)
+/* Free the string at dest and return the string at src. */
+char *free_and_assign(char *dest, char *src)
{
free(dest);
return src;