From owner-freebsd-questions Wed Jan 18 07:52:26 1995 Return-Path: questions-owner Received: (from root@localhost) by freefall.cdrom.com (8.6.9/8.6.6) id HAA05779 for questions-outgoing; Wed, 18 Jan 1995 07:52:26 -0800 Received: from NS.netvision.net.il (root@ns.NetVision.net.il [192.114.201.5]) by freefall.cdrom.com (8.6.9/8.6.6) with ESMTP id HAA05766; Wed, 18 Jan 1995 07:52:18 -0800 Received: from ugen.NetManage.co.il (ugen.netmanage.co.il [192.114.78.165]) by NS.netvision.net.il (8.6.9/8.6.9) with SMTP id RAA09294; Wed, 18 Jan 1995 17:52:02 +0200 Date: Wed, 18 Jan 95 17:50:38 IST From: "Ugen J.S.Antsilevich" Subject: bug in GCC or in lseek/read??? To: freebsd-current@freefall.cdrom.com, freebsd-hackers@freefall.cdrom.com, freebsd-questions@freefall.cdrom.com X-Mailer: Chameleon 4.00-Arm-25, TCP/IP for Windows, NetManage Inc. Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: questions-owner@FreeBSD.org Precedence: bulk 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() replaced in quad_t as 0 and then -size(-5 in this example). on the other hand - is turned into -1 - (-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 #include 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 |