summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c
index 7d30445..e02d807 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -169,9 +169,11 @@ char *feh_unique_filename(char *path, char *basename)
ppid = getpid();
snprintf(cppid, sizeof(cppid), "%06ld", (long) ppid);
+ tmpname = NULL;
/* make sure file doesn't exist */
do {
snprintf(num, sizeof(num), "%06ld", i++);
+ free(tmpname);
tmpname = estrjoin("", path, "feh_", cppid, "_", num, "_", basename, NULL);
}
while (stat(tmpname, &st) == 0);
@@ -183,14 +185,14 @@ char *ereadfile(char *path)
{
char buffer[4096];
FILE *fp;
- int count;
+ size_t count;
fp = fopen(path, "r");
if (!fp)
return NULL;
count = fread(buffer, sizeof(char), sizeof(buffer) - 1, fp);
- if (buffer[count - 1] == '\n')
+ if (count > 0 && buffer[count - 1] == '\n')
buffer[count - 1] = '\0';
else
buffer[count] = '\0';