Date: Wed, 18 Jan 95 17:50:38 IST From: "Ugen J.S.Antsilevich" <ugen@netvision.net.il> To: freebsd-current@freefall.cdrom.com, freebsd-hackers@freefall.cdrom.com, freebsd-questions@freefall.cdrom.com Subject: bug in GCC or in lseek/read??? Message-ID: <Chameleon.950118175745.ugen@ugen.NetManage.co.il>
next in thread | raw e-mail | index | archive | help
Here it comes. I am not sure but it seems like GCC bug in handling quad (long long) types.... Here is the programm.What it tries to do is - to read some buffer from arbitrary file,then lseek back and re-read same place again.Actually i ran into the problemm when really working on very same code. Now look into text and try compiling it,you will see very interesting behaviour. If you'll take a look at assembly code you'll see that -sizeof(<anything>) replaced in quad_t as 0 and then -size(-5 in this example). on the other hand -<number> is turned into -1 -<number> (-1 -5 here). The cast to (int) makes same result and works.The cast to off_t type which is right does not works. Now: lseek returns same value in all cases-both in those where read fails and works. So probably two things here: bug or at least inconsistency in GCC which makes worng conversions + some strange bug in lseek/read calls which i personally can't still figure out.. or may be i am too dumb????? -------------------------CUT HERE(and look in code)----------------------- #include <fcntl.h> #include <unistd.h> main() { int f; char buf[5],buf1[5]; f=open("/bin/ls",O_RDONLY); /* any file actually we don't care */ printf("seek %u\n",lseek(f,100,SEEK_SET)); /* move into the middle somewhere.Actually bug shows without this string */ if (read(f,buf,5)<=0) { printf("First read failed\n"); exit(1); } printf("%d\n",-sizeof(buf)); /* just to show you size of this buffer */ #error ------------ Here choose *ONE* from following 4 strings------- printf("seek %u\n",lseek(f,-sizeof(buf),SEEK_CUR)); /* No cast - does not works */ printf("seek %u\n",lseek(f,(off_t)-sizeof(buf),SEEK_CUR)); /*right cast-does not works */ printf("seek %u\n",lseek(f,(int)-sizeof(buf),SEEK_CUR)); /*wrong cast-works OK*/ printf("seek %u\n",lseek(f,-5,SEEK_CUR)); /* number only-works OK*/ if (read(f,buf1,5)<=0) { printf("Second read failed\n"); /* This one will fail BUT!!! 'errno' is set to 0!!! */ exit(1); } if (!strncmp(buf,buf1,5)) /* just to show thet if everything OK, we read same string */ printf("match\n"); } -------------------------------END----------------------------------- -- -=Ugen J.S.Antsilevich=- NetVision - Israeli Commercial Internet | Learning E-mail: ugen@NetVision.net.il | To Fly. [c] Phone : +972-4-550330 |
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Chameleon.950118175745.ugen>