Date: Thu, 14 Aug 1997 16:44:37 +0200 (CEST) From: Lars Gerhard Kuehl <lgk@BIK-GmbH.DE> To: hackers@freebsd.org Cc: peters@skye.icr.ac.uk, cracauer@cons.org Subject: gcc bug? Message-ID: <Pine.BSF.3.96.970814163730.19864A-100000@eiche.bik-gmbh.de>
next in thread | raw e-mail | index | archive | help
I just encountered quite a seriously strange behaviour of gcc (2.7.2.1 of 2.2.2-RELEASE) (maybe I've only well slept and it's already well known ;). In a program, reading, occasionally manipulating and writing a fairly long string the strings get unhappily shortened. Well I thought I made mistake but it turned out to be a compiler 'option': Using '-O' option: * /* some stuff */ * * fputs(ln, iost->d_out); or * /* some stuff... */ * /* llen and strlen(ln) are expected to be equal */ * * if ( llen != strlen(ln) ); /* <- nota bene */ * fprintf(iost->err, "mist: %d, %d\n", strlen(ln), llen); * * fputs(ln, iost->d_out); cause the line to contain an undesired '\0' somewhere, long before its end. * /* some stuff... */ * * if ( llen != strlen(ln) ) /* <- nota bene */ * fprintf(iost->err, "mist: %d, %d\n", strlen(ln), llen); * * fputs(ln, iost->d_out); In this case the condition is never true, i.e. the string is not truncated. 'ln' is a 10240 byte long char array on the stack of main(). If declaring 'ln' static, the string is truncated at a different location but anyway it is cut as well. This does not happen if compiling with a higher optimisation level or without at all. Do I remember correctly that the kernel is compiled with option '-O'? :-) Lars
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.970814163730.19864A-100000>