diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2016-01-04 13:44:05 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2016-01-04 13:44:05 +0100 |
commit | 63a9747b2e84227e9cdea655ea2ed6891f3eb4ef (patch) | |
tree | e6487b3da87aafbd1ae0d779acae8498764b192c /src | |
parent | whitespace (diff) | |
download | radharc-63a9747b2e84227e9cdea655ea2ed6891f3eb4ef.tar.gz radharc-63a9747b2e84227e9cdea655ea2ed6891f3eb4ef.tar.bz2 radharc-63a9747b2e84227e9cdea655ea2ed6891f3eb4ef.tar.xz |
fix errors
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/haiku.c | 9 | ||||
-rw-r--r-- | src/state.c | 17 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/haiku.c b/src/haiku.c index 5c9e5c7..25387f4 100644 --- a/src/haiku.c +++ b/src/haiku.c @@ -51,16 +51,15 @@ static const char * random_haiku(const char *str, ... /*, NULL */) { int n = 1; - const char *s; + const char *s = str; va_list args; va_start(args, str); - while (va_arg(args, const char *)) n++; + while (va_arg(args, const char *)) n++; va_end(args); - if (n == 1) return str; + if (n == 1) return str; n = random_int(n); - if (!n) return str; va_start(args, str); - while (n--) s = va_arg(args, const char *); + while (n--) s = va_arg(args, const char *); va_end(args); return s; } diff --git a/src/state.c b/src/state.c index 5a22047..cf2a2dd 100644 --- a/src/state.c +++ b/src/state.c @@ -89,9 +89,10 @@ displayenvcmp(const void *a_, const void *b_) static char * escape_display(const char* str) { - char *r, *w, *rc = malloc((2 * strlen(str) + 1) * sizeof(char *)); + char *r, *w, *rc = malloc((2 * strlen(str) + 1) * sizeof(char)); int s = 0; if (!rc) return NULL; + memcpy(rc, str, (strlen(str) + 1) * sizeof(char)); for (r = w = strchr(rc, '=') + 1; *r; r++) { if (!s || (*r != '/')) { if (strchr("@=/", *r)) *w++ = '@'; @@ -99,7 +100,7 @@ escape_display(const char* str) s = (*r == '/'); } } - if (s) w[-2] = '\0'; + w[s ? -2 : 0] = '\0'; return rc; } @@ -123,12 +124,13 @@ get_display_string(const struct settings *settings) if ((settings->monitors_arg[i] == 'd') && strchr(settings->monitors_id[i], '=')) len += 1 + strlen(displays[n++] = settings->monitors_id[i]); if (n) goto custom; + free(displays), displays = NULL; if (!libgamma_list_methods(&method, 1, 0)) { fprintf(stderr, "No display was found.\n" "DRM support missing.\n" "Can you even see?\n"); - return errno = 0, NULL; + return free(displays), errno = 0, NULL; } var = libgamma_method_default_site_variable(method); @@ -137,7 +139,7 @@ get_display_string(const struct settings *settings) try (d = malloc((3 + strlen(var) + strlen(val)) * sizeof(char))); stpcpy(stpcpy(stpcpy(stpcpy(d, "."), var), "="), val); try (rc = escape_display(d)); - return rc; + return free(d), rc; custom: qsort(displays, n, sizeof(*displays), displayenvcmp); @@ -146,10 +148,11 @@ custom: try (d = escape_display(displays[i])); r = stpcpy(stpcpy(r, "."), d), free(d), d = NULL; } + free(displays); return rc; fail: - saved_errno = errno, free(rc), free(d), errno = saved_errno; + saved_errno = errno, free(rc), free(d), free(displays), errno = saved_errno; return NULL; } @@ -164,8 +167,8 @@ int get_state_pathname(const struct settings *settings) { const char *dir = getenv("XGD_RUNTIME_DIR"); - char *display; - char *env; + char *display = NULL; + char *env = NULL; int rc = -1, saved_errno; try (display = get_display_string(settings)); if (!dir || !*dir) dir = "/run"; |