diff --git a/examples/gcoap/gcoap_cli.c b/examples/gcoap/gcoap_cli.c index f1a2f6fb71c358532fb9bdaa62c41d79797b1453..8cb823b8ac2d0aef44f7829ba5de17bad16f89c8 100644 --- a/examples/gcoap/gcoap_cli.c +++ b/examples/gcoap/gcoap_cli.c @@ -233,7 +233,13 @@ int gcoap_cli_cmd(int argc, char **argv) apos++; } - if (argc == apos + 3 || argc == apos + 4) { + /* + * "get" (code_pos 0) must have exactly apos + 3 arguments + * while "post" (code_pos 1) and "put" (code_pos 2) and must have exactly + * apos + 4 arguments + */ + if (((argc == apos + 3) && (code_pos == 0)) || + ((argc == apos + 4) && (code_pos != 0))) { gcoap_req_init(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, code_pos+1, argv[apos+2]); if (argc == apos + 4) { memcpy(pdu.payload, argv[apos+3], strlen(argv[apos+3]));