misc: fix a few minor issues found by static code analysis.

This commit is contained in:
Sam Hocevar
2015-05-30 16:42:25 +02:00
parent 73ec5ee6e4
commit 1c7ffee4a2
4 changed files with 12 additions and 7 deletions
+8 -6
View File
@@ -82,9 +82,9 @@ void zzuf_debug(char const *format, ...)
int ret = _vsnprintf(buf, sizeof(buf), format, args);
if (ret <= 0)
return; /* if _snprintf failed, we send nothing */
goto abort; /* if _snprintf failed, we send nothing */
if (buf[0] == '\0')
return; /* if buf is empty, we don't bother to send it to zzuf */
goto abort; /* if buf is empty, we don't send it */
/* If len >= count, no null-terminator is appended, so we need to
* erase the last character */
@@ -96,8 +96,9 @@ void zzuf_debug(char const *format, ...)
WriteFile(dbg_hdl, buf, ret, &written, NULL);
zzuf_mutex_unlock(&debug_mutex);
}
fflush(NULL); /* flush all streams */
abort:
va_end(args);
fflush(NULL); /* flush all streams to make sure zzuf gotta catch 'em all */
}
void zzuf_debug2(char const *format, ...)
@@ -112,9 +113,9 @@ void zzuf_debug2(char const *format, ...)
int ret = _vsnprintf(buf, sizeof(buf), format, args);
if (ret <= 0)
return; /* if _snprintf failed, we send nothing */
goto abort; /* if _snprintf failed, we send nothing */
if (buf[0] == '\0')
return; /* if buf is empty, we don't bother to send it to zzuf */
goto abort; /* if buf is empty, we don't send it */
/* If len >= count, no null-terminator is appended, so we need to
* erase the last character */
@@ -126,8 +127,9 @@ void zzuf_debug2(char const *format, ...)
WriteFile(dbg_hdl, buf, ret, &written, NULL);
zzuf_mutex_unlock(&debug_mutex);
}
fflush(NULL); /* flush all streams */
abort:
va_end(args);
fflush(NULL); /* flush all streams to make sure zzuf gotta catch 'em all */
}
#else
void zzuf_debug(char const *format, ...)
+1
View File
@@ -417,6 +417,7 @@ static int run(char const *sequence, char const *file)
if (nloops == 0)
{
fprintf(stderr, "E: zzat: ')' outside a loop\n");
free(tmp);
return EXIT_FAILURE;
}
if (loops[nloops - 1].count == 1 || finish)
+1 -1
View File
@@ -739,7 +739,7 @@ static void spawn_children(zzuf_opts_t *opts)
continue;
#ifdef _WIN32
sprintf(tmpname, "%s/zzuf.$i.XXXXXX", tmpdir, GetCurrentProcessId());
sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, GetCurrentProcessId());
int fdout = _open(mktemp(tmpname), _O_RDWR, 0600);
#else
sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, (int)getpid());
+2
View File
@@ -47,6 +47,8 @@ int main(int argc, char *argv[])
uint8_t *tmp = malloc(size);
if (!buf || !tmp)
{
free(buf);
free(tmp);
fprintf(stderr, "zzone: cannot alloc memory\n");
return EXIT_FAILURE;
}