Skip to content

Commit 9597544

Browse files
ikegami-tigaw
authored andcommitted
libnvme/json: check write return value for build warnings
Since the following build warnings output. [61/232] Compiling C object libnvme/src/libnvme-test.so.p/nvme_json.c.o ../libnvme/src/nvme/json.c: In function ‘json_update_config’: ../libnvme/src/nvme/json.c:438:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 438 | write(fd, "\n", 1); | ^~~~~~~~~~~~~~~~~~ [62/232] Compiling C object libnvme/src/libnvme.so.3.0.0.p/nvme_json.c.o ../libnvme/src/nvme/json.c: In function ‘json_update_config’: ../libnvme/src/nvme/json.c:438:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 438 | write(fd, "\n", 1); | ^~~~~~~~~~~~~~~~~~ Fixes: 74b30d2 ("json: update nvme_dump_config to a file descriptor") Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent a781044 commit 9597544

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

libnvme/src/nvme/json.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,9 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd)
435435
ret = json_object_to_fd(fd, json_root,
436436
JSON_C_TO_STRING_PRETTY |
437437
JSON_C_TO_STRING_NOSLASHESCAPE);
438-
write(fd, "\n", 1);
439-
if (ret < 0) {
438+
if (ret < 0 || write(fd, "\n", 1) < 0) {
440439
nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
441-
json_util_get_last_err());
440+
ret ? json_util_get_last_err() : strerror(errno));
442441
ret = -EIO;
443442
}
444443
json_object_put(json_root);

0 commit comments

Comments
 (0)