Skip to content

Commit 726711e

Browse files
chengangclijinxia
authored andcommitted
tools: acrn-crashlog: fix some compiler warnings
This patch is to fix some compiler warnings before enabling the flag to make compiler warning as compiler error. The warning message is like: ignoring return value of ‘write’, declared with attribute warn_unused_result. Tracked-On: #1122 Signed-off-by: CHEN Gang <gang.c.chen@intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Reviewed-by: Liu, Xinwu <xinwu.liu@intel.com>
1 parent 4e17d20 commit 726711e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tools/acrn-crashlog/usercrash/crash_dump.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void loginfo(int fd, const char *fmt, ...)
3131
{
3232
char buf[512];
3333
va_list ap;
34-
size_t len;
34+
size_t len, ret;
3535

3636
va_start(ap, fmt);
3737
vsnprintf(buf, sizeof(buf), fmt, ap);
@@ -41,7 +41,10 @@ static void loginfo(int fd, const char *fmt, ...)
4141
if (len <= 0)
4242
return;
4343

44-
write(fd, buf, len);
44+
ret = write(fd, buf, len);
45+
if (ret != len) {
46+
LOGE("write in loginfo failed\n");
47+
}
4548
}
4649

4750
static const char *get_signame(int sig)
@@ -113,6 +116,7 @@ static int get_backtrace(int pid, int fd, int sig, const char *comm)
113116
{
114117
char *membkt;
115118
char format[FORMAT_LENGTH];
119+
size_t len, ret;
116120

117121
loginfo(fd, "\nBackTrace:\n\n");
118122
memset(format, 0, sizeof(format));
@@ -130,8 +134,13 @@ static int get_backtrace(int pid, int fd, int sig, const char *comm)
130134
LOGE("get gdb info failed\n");
131135
return -1;
132136
}
133-
write(fd, membkt, strlen(membkt));
137+
len = strlen(membkt);
138+
ret = write(fd, membkt, len);
134139
free(membkt);
140+
if (ret != len) {
141+
LOGE("write file failed\n");
142+
return -1;
143+
}
135144
return 0;
136145

137146
}
@@ -159,7 +168,11 @@ static int save_proc_info(int pid, int fd, const char *path, const char *name)
159168
LOGE("read file failed\n");
160169
return -1;
161170
}
162-
write(fd, data, size);
171+
ret = write(fd, data, size);
172+
if ((unsigned long)ret != size) {
173+
LOGE("write file failed\n");
174+
return -1;
175+
}
163176
free(data);
164177
return 0;
165178

0 commit comments

Comments
 (0)