diff --git a/pvattest/src/log.c b/pvattest/src/log.c index 65df2b5e..c79939e0 100644 --- a/pvattest/src/log.c +++ b/pvattest/src/log.c @@ -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) diff --git a/pvattest/src/log.h b/pvattest/src/log.h index ce520b5d..410df62c 100644 --- a/pvattest/src/log.h +++ b/pvattest/src/log.h @@ -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 */