From 7bb18feb92815eec1c54b882ce5ab64c72c9580d Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 15 Aug 2006 20:29:02 +0000 Subject: [PATCH] Shifts left and right by 32 were tripping a gcc warning (fatal with -Werror, of course) about shifting by more than the range of a data type. They only appeared in `if' statements testing sizeof(off_t), but gcc warns even when the code is unreachable. I've removed the conditional code (the general case should still work even on 32-bit machines), and hacked each shift by 32 into a pair of shifts by 16. Note that the gcc warning is not just a helpful indication that you may be using the wrong data type; it's actually pointing out ANSI- undefined behaviour in shifting a signed integer beyond the size of its type. git-svn-id: svn://svn.tartarus.org/sgt/putty@6789 cda61777-01e9-0310-a592-d414129be87e --- unix/uxsftp.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 8db397ad..fd6b528b 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -143,14 +143,9 @@ RFile *open_existing_file(char *name, uint64 *size, memset(&statbuf, 0, sizeof(statbuf)); } - if (size) { - if (sizeof(statbuf.st_size) == 8) { - size->hi = statbuf.st_size >> 32; - size->lo = (long) statbuf.st_size; - } else { - *size = uint64_make(0, statbuf.st_size); - } - } + if (size) + *size = uint64_make((statbuf.st_size >> 16) >> 16, + statbuf.st_size); if (mtime) *mtime = statbuf.st_mtime; @@ -214,12 +209,8 @@ WFile *open_existing_wfile(char *name, uint64 *size) memset(&statbuf, 0, sizeof(statbuf)); } - if (sizeof(statbuf.st_size) == 8) { - size->hi = statbuf.st_size >> 32; - size->lo = (long) statbuf.st_size; - } else { - *size = uint64_make(0, statbuf.st_size); - } + *size = uint64_make((statbuf.st_size >> 16) >> 16, + statbuf.st_size); } return ret; @@ -273,11 +264,7 @@ int seek_file(WFile *f, uint64 offset, int whence) off_t fileofft; int lseek_whence; - if (sizeof(off_t) == 8) { - fileofft = ((off_t) offset.hi << 32) + offset.lo; - } else { - fileofft = offset.lo; - } + fileofft = (((off_t) offset.hi << 16) << 16) + offset.lo; switch (whence) { case FROM_START: @@ -303,12 +290,7 @@ uint64 get_file_posn(WFile *f) fileofft = lseek(f->fd, (off_t) 0, SEEK_CUR); - if (sizeof(off_t) == 8) { - ret.hi = fileofft >> 32; - ret.lo = (long) fileofft; - } else { - ret = uint64_make(0, fileofft); - } + ret = uint64_make((fileofft >> 16) >> 16, fileofft); return ret; } -- 2.11.0