Message ID | 1412237788-20611-4-git-send-email-patrick@georgi-clan.de |
---|---|
State | Changes Requested, archived |
Headers | show |
On 10/02/2014 02:16 AM, Patrick Georgi wrote: > This could silently fail which leads to surprising behaviour. > diff --git a/src/set.c b/src/set.c > - fseek(fp, offset, SEEK_SET); > + if (!fseek(fp, offset, SEEK_SET)) { fseek is supposed to return the current offset, or -1 on error. I think that should say if (fseek(...) < 0) or if (fseek(...) == -1)) or if (fseek(...) != offset). -- To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Am 03.10.2014 um 00:58 schrieb Stephen Warren:
> fseek is supposed to return the current offset, or -1 on error. I
The man page on my system disagrees: "Upon successful completion, fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current offset. Otherwise, -1 is returned and errno is set to indicate the error."
Patrick
On 10/03/2014 12:54 AM, Patrick Georgi wrote: > Am 03.10.2014 um 00:58 schrieb Stephen Warren: >> fseek is supposed to return the current offset, or -1 on error. I > > The man page on my system disagrees: "Upon successful completion, fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current offset. Otherwise, -1 is returned and errno is set to indicate the error." That seems to exactly match what I said. -- To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/src/set.c b/src/set.c index ff32b53..907d640 100644 --- a/src/set.c +++ b/src/set.c @@ -59,7 +59,11 @@ read_from_image(char *filename, return result; } - fseek(fp, offset, SEEK_SET); + if (!fseek(fp, offset, SEEK_SET)) { + printf("Error: Couldn't seek to %s(%d)\n", filename, offset); + result = 1; + goto cleanup; + } if (stat(filename, &stats) != 0) { printf("Error: Unable to query info on bootloader path %s\n",
This could silently fail which leads to surprising behaviour. Found-by: Coverity Scan Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> --- src/set.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)