Fix sending \0 in client mode.
This commit is contained in:
parent
f57b204029
commit
c06aad7cdc
1 changed files with 7 additions and 9 deletions
14
netcalc.c
14
netcalc.c
|
@ -246,25 +246,23 @@ int client()
|
|||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue