Compile error netio.c:349 "ignoring return value of ‘asprintf’"
huguei opened this issue · 1 comments
huguei commented
There's a compile error from a warning in netio.c:
netio.c:349:4: error: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Werror=unused-result]
349 | asprintf(&temp, "%s%*.*s\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
350 | or_else(writer->ps_buf, ""),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
351 | (int)pre_len, (int)pre_len, fetch->buf);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:60: netio.o] Error 1
It can be solved explicitly ignoring the return value with a void cast:
index ea559a5..3054c91 100644
--- a/netio.c
+++ b/netio.c
@@ -346,7 +346,7 @@ writer_func(char *ptr, size_t size, size_t nmemb, void *blob) {
/* concatenate this fragment (with \n) to info_buf. */
char *temp = NULL;
- asprintf(&temp, "%s%*.*s\n",
+ (void) !asprintf(&temp, "%s%*.*s\n",
or_else(writer->ps_buf, ""),
(int)pre_len, (int)pre_len, fetch->buf);
DESTROY(writer->ps_buf);
djw1149 commented
Thank you Hugo. I pushed a fix that instead checks the return value and does a my_panic if it's negative, as we do elsewhere.