diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-10-02 15:48:50 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-10-02 15:48:50 -0400 |
commit | 31fb2e4c62abad26f0581024d3d5f9bc486471c1 (patch) | |
tree | 07f731dd5c142253f381f98ed0110cb23e1c8282 /parse-xml.c | |
parent | 6b0d9adb61472866d584a11b71ac1a71753c5ca6 (diff) | |
download | subsurface-31fb2e4c62abad26f0581024d3d5f9bc486471c1.tar.gz |
Avoid possible sign extension
Interesting theoretical bug (it'll be a while before we run into this
one).
Coverity CID 1307979
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/parse-xml.c b/parse-xml.c index a822395a7..46261e9c9 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -3269,7 +3269,9 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size) snprintf(serial, sizeof(serial), "%d", (ptr[7] << 8) + ptr[6]); cur_dc->serial = strdup(serial); // Dive start time in seconds since 2000-01-01 00:00 - cur_dc->when = (ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + ptr[8] + 946684800; + // let's avoid implicit sign extensions (as timestamp_t is signed) + uint32_t offset = (ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + ptr[8]; + cur_dc->when = offset + 946684800; cur_dive->when = cur_dc->when; cur_dc->duration.seconds = ((ptr[14] & 0xFE) << 16) + (ptr[13] << 8) + ptr[12]; |