diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2020-08-08 19:34:30 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2020-08-08 19:37:57 +0000 |
| commit | 7a77958ba20c2b344be5e66e69e2f212a4bbf6b3 (patch) | |
| tree | cdb8191177f5f9ca69ea7858f9543f36fcbcf616 /osc.c | |
| parent | changelog: add birger to 'contributers' for the upcoming release (diff) | |
Convert most dynamic allocations to use functions from xmalloc.h
Diffstat (limited to 'osc.c')
| -rw-r--r-- | osc.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -2,6 +2,7 @@ #include <string.h> #include <ctype.h> +#include <errno.h> #include <limits.h> #include <unistd.h> @@ -14,6 +15,7 @@ #include "selection.h" #include "terminal.h" #include "vt.h" +#include "xmalloc.h" #define UNHANDLED() LOG_DBG("unhandled: OSC: %.*s", (int)term->vt.osc.idx, term->vt.osc.data) @@ -22,13 +24,16 @@ osc_to_clipboard(struct terminal *term, const char *target, const char *base64_data) { char *decoded = base64_decode(base64_data); - LOG_DBG("decoded: %s", decoded); - if (decoded == NULL) { - LOG_WARN("OSC: invalid clipboard data: %s", base64_data); + if (errno == EINVAL) + LOG_WARN("OSC: invalid clipboard data: %s", base64_data); + else + LOG_ERRNO("base64_decode() failed"); return; } + LOG_DBG("decoded: %s", decoded); + bool to_clipboard = false; bool to_primary = false; @@ -67,13 +72,13 @@ osc_to_clipboard(struct terminal *term, const char *target, } if (to_clipboard) { - char *copy = strdup(decoded); + char *copy = xstrdup(decoded); if (!text_to_clipboard(seat, term, copy, seat->kbd.serial)) free(copy); } if (to_primary) { - char *copy = strdup(decoded); + char *copy = xstrdup(decoded); if (!text_to_primary(seat, term, copy, seat->kbd.serial)) free(copy); } @@ -184,7 +189,7 @@ osc_from_clipboard(struct terminal *term, const char *source) term_to_slave(term, &src, 1); term_to_slave(term, ";", 1); - struct clip_context *ctx = malloc(sizeof(*ctx)); + struct clip_context *ctx = xmalloc(sizeof(*ctx)); *ctx = (struct clip_context) {.seat = seat, .term = term}; switch (src) { @@ -374,7 +379,7 @@ osc_set_pwd(struct terminal *term, char *string) /* Decode %xx encoded characters */ const char *path = hostname_end; - char *pwd = malloc(strlen(path) + 1); + char *pwd = xmalloc(strlen(path) + 1); char *p = pwd; while (true) { |
