diff options
author | Tormod Volden <debian.tormod@gmail.com> | 2022-01-22 14:39:45 +0100 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2022-01-22 14:47:17 +0100 |
commit | afcd360005dcbd3d9e6ed2d6e0255a7ad9efd3a7 (patch) | |
tree | b2c941f8dd1cf2cd4c12b57f33e49341b8c8ebf6 /examples/ezusb.c | |
parent | 65b786f77d78df53c41c064ae958dffad1bbe222 (diff) | |
download | libusb-afcd360005dcbd3d9e6ed2d6e0255a7ad9efd3a7.tar.gz |
examples: Do not assume positive errno macros
Some functions were returning e.g. -ENOMEM and the caller would check
for negative return values. However, on Haiku, contrary to modern
standards, these macros are negative, so this logic would fail. In any
case, change the function to return -1 instead. For good measure also
set errno to the appropriate value, although it is not used in the
current code.
This was discovered on Haiku builds because the value for ENOMEM is
INT_MIN which cannot be negated without overflow.
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Diffstat (limited to 'examples/ezusb.c')
-rw-r--r-- | examples/ezusb.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/examples/ezusb.c b/examples/ezusb.c index ec60b0e..4bed12a 100644 --- a/examples/ezusb.c +++ b/examples/ezusb.c @@ -139,7 +139,11 @@ static int ezusb_write(libusb_device_handle *device, const char *label, else logerror("%s ==> %d\n", label, status); } - return (status < 0) ? -EIO : 0; + if (status < 0) { + errno = EIO; + return -1; + } + return 0; } /* @@ -162,7 +166,11 @@ static int ezusb_read(libusb_device_handle *device, const char *label, else logerror("%s ==> %d\n", label, status); } - return (status < 0) ? -EIO : 0; + if (status < 0) { + errno = EIO; + return -1; + } + return 0; } /* @@ -514,7 +522,8 @@ static int ram_poke(void *context, uint32_t addr, bool external, if (external) { logerror("can't write %u bytes external memory at 0x%08x\n", (unsigned)len, addr); - return -EINVAL; + errno = EINVAL; + return -1; } break; case skip_internal: /* CPU must be running */ @@ -538,7 +547,8 @@ static int ram_poke(void *context, uint32_t addr, bool external, case _undef: default: logerror("bug\n"); - return -EDOM; + errno = EDOM; + return -1; } ctx->total += len; |