Shifts left and right by 32 were tripping a gcc warning (fatal with
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 15 Aug 2006 20:29:02 +0000 (20:29 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 15 Aug 2006 20:29:02 +0000 (20:29 +0000)
-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

index 8db397a..fd6b528 100644 (file)
@@ -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;
 }