Skip to content

Commit 191a098

Browse files
ikegami-tigaw
authored andcommitted
nvme-print: use allocation error string variable
Use the variable instead of the hardcorded and duplicated strings. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent e4ffd65 commit 191a098

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

nvme-print-json.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void obj_add_result(struct json_object *o, const char *v, ...)
119119
va_start(ap, v);
120120

121121
if (vasprintf(&value, v, ap) < 0)
122-
value = "Could not allocate string";
122+
value = alloc_error;
123123

124124
obj_add_str(o, "Result", value);
125125

@@ -135,7 +135,7 @@ static void obj_add_key(struct json_object *o, const char *k, const char *v, ...
135135
va_start(ap, v);
136136

137137
if (vasprintf(&value, v, ap) < 0)
138-
value = "Could not allocate string";
138+
value = alloc_error;
139139

140140
obj_add_str(o, k, value);
141141

@@ -4582,7 +4582,7 @@ static void json_output_error_status(int status, const char *msg, va_list ap)
45824582
_cleanup_free_ char *value = NULL;
45834583

45844584
if (vasprintf(&value, msg, ap) < 0)
4585-
value = "Could not allocate string";
4585+
value = alloc_error;
45864586

45874587
sprintf(json_str, "Error: %s", value);
45884588
r = obj_create(json_str);
@@ -4622,7 +4622,7 @@ static void json_output_message(bool error, const char *msg, va_list ap)
46224622
_cleanup_free_ char *value = NULL;
46234623

46244624
if (vasprintf(&value, msg, ap) < 0)
4625-
value = "Could not allocate string";
4625+
value = alloc_error;
46264626

46274627
obj_add_str(r, error ? "error" : "result", value);
46284628

@@ -4636,7 +4636,7 @@ static void json_output_perror(const char *msg, va_list ap)
46364636
_cleanup_free_ char *error = NULL;
46374637

46384638
if (vasprintf(&error, msg, ap) < 0)
4639-
error = "Could not allocate string";
4639+
error = alloc_error;
46404640

46414641
obj_add_key(r, "error", "%s: %s", error, strerror(errno));
46424642

nvme-print-stdout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5609,7 +5609,7 @@ static void stdout_perror(const char *msg, va_list ap)
56095609
_cleanup_free_ char *error = NULL;
56105610

56115611
if (vasprintf(&error, msg, ap) < 0)
5612-
error = "Could not allocate string";
5612+
error = alloc_error;
56135613

56145614
perror(error);
56155615
}

nvme-print.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define nvme_print_output_format(name, ...) \
2727
nvme_print(name, nvme_is_output_format_json() ? JSON : NORMAL, ##__VA_ARGS__);
2828

29+
char *alloc_error = "Could not allocate string";
30+
2931
static struct print_ops *nvme_print_ops(nvme_print_flags_t flags)
3032
{
3133
struct print_ops *ops = NULL;

nvme-print.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,6 @@ void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print
352352
void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags);
353353
void nvme_show_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log,
354354
nvme_print_flags_t flags);
355+
356+
extern char *alloc_error;
355357
#endif /* NVME_PRINT_H */

0 commit comments

Comments
 (0)