diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-21 23:12:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-21 23:12:00 +0200 |
commit | b14feb7ffbe390762c2bdb4e2e6cc200b2369835 (patch) | |
tree | 392bfe8b46aaa6dfbd5a478c82aeb5c918fd6f0d /src | |
parent | Add libcoopgamma_get_crtcs_recv.3 (diff) | |
download | libcoopgamma-b14feb7ffbe390762c2bdb4e2e6cc200b2369835.tar.gz libcoopgamma-b14feb7ffbe390762c2bdb4e2e6cc200b2369835.tar.bz2 libcoopgamma-b14feb7ffbe390762c2bdb4e2e6cc200b2369835.tar.xz |
Add missing part of check_error: copy description (and of course call next_payload)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcoopgamma.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c index c6459f4..769b7b8 100644 --- a/src/libcoopgamma.c +++ b/src/libcoopgamma.c @@ -1736,6 +1736,8 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_ int have_in_response_to = 0; int have_error = 0; int bad = 0; + char* payload; + size_t n; for (;;) { @@ -1789,14 +1791,27 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_ return 0; } - if (bad || (have_in_response_to != 1) || (have_error != 1)) + payload = next_payload(ctx, &n); + if (payload != NULL) { - errno = EBADMSG; - copy_errno(ctx); - return -1; + if (memchr(ctx, '\0', n) || (payload[n - 1] != '\n')) + goto badmsg; + ctx->error.description = malloc(n); + if (ctx->error.description == NULL) + goto fail; + memcpy(ctx->error.description, payload, n - 1); + ctx->error.description[n - 1] = '\0'; } + if (bad || (have_in_response_to != 1) || (have_error != 1)) + goto badmsg; + return 1; +badmsg: + errno = EBADMSG; +fail: + copy_errno(ctx); + return -1; } |