Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: Mirsad Todorovac
Subject: Using uninitialized variable w/o warning
Date: 8 Aug 2003, 16:33:04
I+'m having an uninitialized string s1 used in ValBase(), and
-Wuninitialized wouldn't work:
bash-2.05b$ gpc --automake -Wall -O3 -Wuninitialized mir048d.pas
bash-2.05b$ gpc --automake -Wall -O0 -Wuninitialized mir048d.pas
gpc1: warning: -Wuninitialized is not supported without -O
bash-2.05b$
bash-2.05b$ gpc --automake -Wall -O2 -Wuninitialized mir048d.pas
bash-2.05b$ gpc --automake -Wall -O1 -Wuninitialized mir048d.pas
program mir048d;
{Integer2StringBase(), checking converted value}
uses GPC;
const NTestConvs = 2048;
var x : LongInt;
i, Base, Width, ec : Integer;
s : String (4096);
RandomSeed : Integer;
procedure ValBase (s: String; var y: LongInt; ec: Integer; Base: Integer);
var s1 : String (4096);
begin
if s[1] = '-' then
s1 := '-' + Integer2String (Base) + '#' + s[2..Length (s)]
else
s1 := Integer2String (Base) + '#' + s1; {uninitialized s1 used here}
Val (s1, y, ec);
end;
procedure TestConv (x : LongInt);
var y : LongInt;
begin
for Base in [2, 3, 4, 7, 8, 9, 12, 13, 16, 24, 36] do { actually, only
2, 8, 16 are special }
begin
s := Integer2StringBase (x, Base);
ValBase (s, y, ec, Base);
if x <> y then
begin
WriteLn ('failed: value (x y) = (', x, '/', y, ')=', s);
Halt
end;
if ec <> 0 then
begin
WriteLn ('failed: garbled characters at end: s = ', s);
Halt
end
end
end;
begin
RandomSeed := Random (MaxInt);
SeedRandom (RandomSeed);
Width := 0;
for i := 1 to NTestConvs do
begin
x := Random ($ffffffff);
TestConv (x);
TestConv (-x);
end;
for i := 1 to NTestConvs do
begin
x := Random ($7fffffffffffffff);
TestConv (x);
TestConv (-x);
end;
TestConv (0);
TestConv (-1);
TestConv (-9223372036854775808);
TestConv (9223372036854775807);
WriteLn ('OK')
end.
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Frank Heckenbach | Using uninitialized variable w/o warning | 12 Aug 2003, 01:41:30 |
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).