From c06aad7cdc75d1bf36eaaab0a81347ef1b02ee01 Mon Sep 17 00:00:00 2001 From: "tim.schubert@tu-bs.de" Date: Fri, 28 Oct 2016 18:58:46 +0200 Subject: [PATCH] Fix sending \0 in client mode. --- netcalc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/netcalc.c b/netcalc.c index 51cc466..44d3364 100644 --- a/netcalc.c +++ b/netcalc.c @@ -245,26 +245,24 @@ int client() unsigned int num1; unsigned int num2; char op; - - int status = parse(line, sizeof buf, &num1, &num2, &op); + memset(buf, 0, BUFLEN); + int status = parse(line, strlen(line)+1, &num1, &num2, &op); + if (status == -1) { report_error(buf, BUFLEN, "parse: failed to parse"); - continue; } else if (status == -2) { - op = '+'; - num2 = 0; + sprintf(buf, "%u%c%u", num1, '+', "0"); + } else { + sprintf(buf, "%u%c%u", num1, op, num2); } - sprintf(buf, "%u%c%u", num1, op, num2); - - if (send(SOCKFD, buf, strlen(buf), 0) == -1) { + if (send(SOCKFD, buf, strlen(buf)+1, 0) == -1) { perror("recv"); continue; } - free(line); line = NULL; // so getline allocates a buffer for us