From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 08/20] contrib/elf2dmp: Fix error reporting style in pdb.c
Date: Mon, 11 Mar 2024 19:12:29 +0000 [thread overview]
Message-ID: <20240311191241.4177990-9-peter.maydell@linaro.org> (raw)
In-Reply-To: <20240311191241.4177990-1-peter.maydell@linaro.org>
From: Akihiko Odaki <akihiko.odaki@daynix.com>
include/qapi/error.h says:
> We recommend
> * bool-valued functions return true on success / false on failure,
> ...
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20240307-elf2dmp-v4-7-4f324ad4d99d@daynix.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
contrib/elf2dmp/pdb.h | 2 +-
contrib/elf2dmp/main.c | 2 +-
contrib/elf2dmp/pdb.c | 50 +++++++++++++++++++++---------------------
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h
index 2a50da56ac9..feddf1862f0 100644
--- a/contrib/elf2dmp/pdb.h
+++ b/contrib/elf2dmp/pdb.h
@@ -233,7 +233,7 @@ struct pdb_reader {
size_t segs_size;
};
-int pdb_init_from_file(const char *name, struct pdb_reader *reader);
+bool pdb_init_from_file(const char *name, struct pdb_reader *reader);
void pdb_exit(struct pdb_reader *reader);
uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name);
uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name);
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index d295fd92be2..7a3a7225905 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -596,7 +596,7 @@ int main(int argc, char *argv[])
goto out_ps;
}
- if (pdb_init_from_file(PDB_NAME, &pdb)) {
+ if (!pdb_init_from_file(PDB_NAME, &pdb)) {
eprintf("Failed to initialize PDB reader\n");
goto out_pdb_file;
}
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index abf17c2e7c1..1c505142518 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -158,30 +158,30 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number)
return pdb_ds_read(r->ds.header, block_list, file_size[file_number]);
}
-static int pdb_init_segments(struct pdb_reader *r)
+static bool pdb_init_segments(struct pdb_reader *r)
{
unsigned stream_idx = r->segments;
r->segs = pdb_ds_read_file(r, stream_idx);
if (!r->segs) {
- return 1;
+ return false;
}
r->segs_size = pdb_get_file_size(r, stream_idx);
if (!r->segs_size) {
- return 1;
+ return false;
}
- return 0;
+ return true;
}
-static int pdb_init_symbols(struct pdb_reader *r)
+static bool pdb_init_symbols(struct pdb_reader *r)
{
PDB_SYMBOLS *symbols;
symbols = pdb_ds_read_file(r, 3);
if (!symbols) {
- return 1;
+ return false;
}
r->symbols = symbols;
@@ -198,18 +198,18 @@ static int pdb_init_symbols(struct pdb_reader *r)
goto out_symbols;
}
- return 0;
+ return true;
out_symbols:
g_free(symbols);
- return 1;
+ return false;
}
-static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
+static bool pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
{
if (hdr->block_size == 0) {
- return 1;
+ return false;
}
memset(r->file_used, 0, sizeof(r->file_used));
@@ -218,22 +218,22 @@ static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
hdr->toc_page * hdr->block_size), hdr->toc_size);
if (!r->ds.toc) {
- return 1;
+ return false;
}
- return 0;
+ return true;
}
-static int pdb_reader_init(struct pdb_reader *r, void *data)
+static bool pdb_reader_init(struct pdb_reader *r, void *data)
{
const char pdb7[] = "Microsoft C/C++ MSF 7.00";
if (memcmp(data, pdb7, sizeof(pdb7) - 1)) {
- return 1;
+ return false;
}
- if (pdb_reader_ds_init(r, data)) {
- return 1;
+ if (!pdb_reader_ds_init(r, data)) {
+ return false;
}
r->ds.root = pdb_ds_read_file(r, 1);
@@ -241,15 +241,15 @@ static int pdb_reader_init(struct pdb_reader *r, void *data)
goto out_ds;
}
- if (pdb_init_symbols(r)) {
+ if (!pdb_init_symbols(r)) {
goto out_root;
}
- if (pdb_init_segments(r)) {
+ if (!pdb_init_segments(r)) {
goto out_sym;
}
- return 0;
+ return true;
out_sym:
pdb_exit_symbols(r);
@@ -258,7 +258,7 @@ out_root:
out_ds:
pdb_reader_ds_exit(r);
- return 1;
+ return false;
}
static void pdb_reader_exit(struct pdb_reader *r)
@@ -269,7 +269,7 @@ static void pdb_reader_exit(struct pdb_reader *r)
pdb_reader_ds_exit(r);
}
-int pdb_init_from_file(const char *name, struct pdb_reader *reader)
+bool pdb_init_from_file(const char *name, struct pdb_reader *reader)
{
GError *gerr = NULL;
void *map;
@@ -278,21 +278,21 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader)
if (gerr) {
eprintf("Failed to map PDB file \'%s\'\n", name);
g_error_free(gerr);
- return 1;
+ return false;
}
reader->file_size = g_mapped_file_get_length(reader->gmf);
map = g_mapped_file_get_contents(reader->gmf);
- if (pdb_reader_init(reader, map)) {
+ if (!pdb_reader_init(reader, map)) {
goto out_unmap;
}
- return 0;
+ return true;
out_unmap:
g_mapped_file_unref(reader->gmf);
- return 1;
+ return false;
}
void pdb_exit(struct pdb_reader *reader)
--
2.34.1
next prev parent reply other threads:[~2024-03-11 19:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 19:12 [PULL 00/20] target-arm queue Peter Maydell
2024-03-11 19:12 ` [PULL 01/20] hw/arm: Deprecate various old Arm machine types Peter Maydell
2024-03-11 19:12 ` [PULL 02/20] contrib/elf2dmp: Remove unnecessary err flags Peter Maydell
2024-03-11 19:12 ` [PULL 03/20] contrib/elf2dmp: Assume error by default Peter Maydell
2024-03-11 19:12 ` [PULL 04/20] contrib/elf2dmp: Continue even contexts are lacking Peter Maydell
2024-03-11 19:12 ` [PULL 05/20] contrib/elf2dmp: Change pa_space_create() signature Peter Maydell
2024-03-11 19:12 ` [PULL 06/20] contrib/elf2dmp: Fix error reporting style in addrspace.c Peter Maydell
2024-03-11 19:12 ` [PULL 07/20] contrib/elf2dmp: Fix error reporting style in download.c Peter Maydell
2024-03-11 19:12 ` Peter Maydell [this message]
2024-03-11 19:12 ` [PULL 09/20] contrib/elf2dmp: Fix error reporting style in qemu_elf.c Peter Maydell
2024-03-11 19:12 ` [PULL 10/20] contrib/elf2dmp: Fix error reporting style in main.c Peter Maydell
2024-03-11 19:12 ` [PULL 11/20] contrib/elf2dmp: Always check for PA resolution failure Peter Maydell
2024-03-11 19:12 ` [PULL 12/20] contrib/elf2dmp: Always destroy PA space Peter Maydell
2024-03-11 19:12 ` [PULL 13/20] contrib/elf2dmp: Ensure segment fits in file Peter Maydell
2024-03-11 19:12 ` [PULL 14/20] contrib/elf2dmp: Use lduw_le_p() to read PDB Peter Maydell
2024-03-11 19:12 ` [PULL 15/20] contrib/elf2dmp: Use rol64() to decode Peter Maydell
2024-03-11 19:12 ` [PULL 16/20] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer Peter Maydell
2024-03-11 19:12 ` [PULL 17/20] contrib/elf2dmp: Use GPtrArray Peter Maydell
2024-03-11 19:12 ` [PULL 18/20] contrib/elf2dmp: Clamp QEMU note to file size Peter Maydell
2024-03-11 19:12 ` [PULL 19/20] contrib/elf2dmp: Ensure phdrs fit in file Peter Maydell
2024-03-11 19:12 ` [PULL 20/20] docs: update copyright date to the year 2024 Peter Maydell
2024-03-12 13:07 ` [PULL 00/20] target-arm queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240311191241.4177990-9-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).