mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
pvattest: pvattest_hexdump: add error checks
`fprintf` can fail, therefore check the return code of it. Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
bec9d1dfcd
commit
8fe214d915
+23
-13
@@ -159,8 +159,8 @@ void pvattest_log_bytes(const void *data, size_t size, size_t width, const char
|
||||
g_log(PVATTEST_BYTES_LOG_DOMAIN, log_lvl, "\n");
|
||||
}
|
||||
|
||||
void pvattest_hexdump(FILE *stream, GBytes *bytes, const size_t width, const char *prefix,
|
||||
const gboolean beautify)
|
||||
int pvattest_hexdump(FILE *stream, GBytes *bytes, const size_t width, const char *prefix,
|
||||
const gboolean beautify)
|
||||
{
|
||||
const uint8_t *data;
|
||||
size_t size;
|
||||
@@ -171,25 +171,35 @@ void pvattest_hexdump(FILE *stream, GBytes *bytes, const size_t width, const cha
|
||||
data = g_bytes_get_data(bytes, &size);
|
||||
pv_wrapped_g_assert(data);
|
||||
|
||||
if (beautify)
|
||||
fprintf(stream, "%s0x0000 ", prefix);
|
||||
else
|
||||
fprintf(stream, "%s", prefix);
|
||||
if (beautify) {
|
||||
if (fprintf(stream, "%s0x0000 ", prefix) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (fprintf(stream, "%s", prefix) < 0)
|
||||
return -1;
|
||||
}
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
fprintf(stream, "%02x", data[i]);
|
||||
if (i % 2 == 1 && beautify)
|
||||
fprintf(stream, " ");
|
||||
if (fprintf(stream, "%02x", data[i]) < 0)
|
||||
return -1;
|
||||
if (i % 2 == 1 && beautify) {
|
||||
if (fprintf(stream, " ") < 0)
|
||||
return -1;
|
||||
}
|
||||
if (i == size - 1)
|
||||
break;
|
||||
if (width == 0)
|
||||
continue;
|
||||
if (i % width == width - 1) {
|
||||
if (beautify)
|
||||
fprintf(stream, "\n%s0x%04lx ", prefix, i + 1);
|
||||
else
|
||||
fprintf(stream, "\n%s", prefix);
|
||||
if (beautify) {
|
||||
if (fprintf(stream, "\n%s0x%04lx ", prefix, i + 1) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (fprintf(stream, "\n%s", prefix) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pvattest_log_GError(const char *info, GError *error)
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ void pvattest_log_plain_logger(const char *log_domain, GLogLevelFlags level, con
|
||||
}
|
||||
void pvattest_log_bytes(const void *data, size_t size, size_t width, const char *prefix,
|
||||
gboolean beautify, GLogLevelFlags log_lvl) PV_NONNULL(1);
|
||||
void pvattest_hexdump(FILE *stream, GBytes *bytes, const size_t width, const char *prefix,
|
||||
const gboolean beautify) PV_NONNULL(1, 2);
|
||||
int pvattest_hexdump(FILE *stream, GBytes *bytes, const size_t width, const char *prefix,
|
||||
const gboolean beautify) PV_NONNULL(1, 2);
|
||||
void pvattest_log_GError(const char *info, GError *error) PV_NONNULL(1);
|
||||
|
||||
#endif /* PVATTEST_LOG_H */
|
||||
|
||||
Reference in New Issue
Block a user