473,473 Members | 3,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is this wrong or is splint broken?

I can see no problem [1] with the loop below, and gcc compiles it
without complaining no matter how many warnings I enable, but
splint has a parse error on line 103 (marked below), column 22. Is
it seriously broken, or am I missing something?

while (!done) { /* line 76 */
switch (getans("Hit, Stand, suRrender, or Double down? ",
"hsrd")) {
case 'r':
credit -= wager / 2;
goto restart;
case 'd':
if (credit < 2 * wager) {
puts("You don't have enough money.");
break;
} else {
wager *= 2;
done = 1;
}
/* fall through */
case 'h':
card = drawcard(&deck);
printf("You got: %s of %s. ",
cardnames[card.rank], suitnames[card.suit]);
add_to_hand(card, &plhand);
printf("Your score is %u.\n", plhand.score);
if (plhand.bust) {
puts("You busted.");
/* fall through */
case 's':
done = 1;
}
break; /* line 103; column 22 is the semicolon. */
default:
fputs("End-of-file encountered or read error.\n", stderr);
exit(EXIT_FAILURE);
}
if (plhand.score == 21)
done = 1;
}

[1] I know that goto is evil, but I had to jump out of a switch
statement and two while statements at once, without jumping out of
the outermost of the three while statements...
--
Army1987 (Replace "NOSPAM" with "email")
"Never attribute to malice that which can be adequately explained
by stupidity." -- R. J. Hanlon (?)

Aug 7 '07 #1
3 2371

Army1987 wrote:
I can see no problem [1] with the loop below, and gcc compiles it
without complaining no matter how many warnings I enable, but
splint has a parse error on line 103 (marked below), column 22. Is
it seriously broken, or am I missing something?
Hi there,

IMHO the code seems fine. You've got a case label within an if {}
block - I imagine this is why splint is whining. It's probably trying
to balance { and }, and wants to do so within basic blocks, and so it
probably gets confused because it thinks the case statement is the
start of another basic block.

Looks similar to Duff's device. Might be interesting to see what
splint says about that. I'd guess splint is broken in this respect.

Hope that helps, probably won't :)

Doug

Aug 7 '07 #2
On Aug 8, 2:53 am, Army1987 <army1...@NOSPAM.itwrote:
I can see no problem [1] with the loop below, and gcc compiles it
without complaining no matter how many warnings I enable, but
splint has a parse error on line 103 (marked below), column 22. Is
if (plhand.bust) {
puts("You busted.");
/* fall through */
case 's':
done = 1;
}
break; /* line 103; column 22 is the semicolon. */
Obv it doesn't like the case label within the
if block. Note that it is simple to restructure
the code to not use this hack, e.g.:

if ( plhand.bust )
{
puts("You busted");
done = 1;
}
break;

case s:
done = 1;

which I think is easier to read too.
If you really must share the cases (e.g. if there
is a lot of extra code you haven't shown), then:

if ( !plhand.bust )
break;

puts("You busted");
case 's':
done = 1;

Aug 7 '07 #3
On Tue, 07 Aug 2007 09:07:06 -0700, Doug wrote:
>
Army1987 wrote:
>I can see no problem [1] with the loop below, and gcc compiles it
without complaining no matter how many warnings I enable, but
splint has a parse error on line 103 (marked below), column 22. Is
it seriously broken, or am I missing something?

Hi there,

IMHO the code seems fine. You've got a case label within an if {}
block - I imagine this is why splint is whining. It's probably trying
to balance { and }, and wants to do so within basic blocks, and so it
probably gets confused because it thinks the case statement is the
start of another basic block.
Yes, it is that which confuses it.
army1987@army1987-laptop:~$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
extern int is_prime(unsigned);
int main(void)
{
unsigned k = 0;
if (scanf("%u", &k) < 1) {
fputs("Invalid\n", stderr);
exit(EXIT_FAILURE);
}
switch (k) {
case 0:
case 1:
puts("k is neither prime nor composite");
break;
default:
if (is_prime(k))
case 2:
case 3:
case 5:
puts("k is prime");
else
case 4:
case 6:
puts("k is composite");
}
return 0;
}
army1987@army1987-laptop:~$ splint foo.c
Splint 3.1.1 --- 20 Jun 2006

foo.c: (in function main)
foo.c:8:2: Return value (type int) ignored: fputs("Invalid\n...
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
foo.c:14:2: Return value (type int) ignored: puts("k is neith...
foo.c:17:6: Test expression for if not boolean, type int: is_prime(k)
Test expression type is not boolean or int. (Use -predboolint to inhibit
warning)
foo.c:19:9: Parse Error: Likely parse error. Conditional clauses are
inconsistent.. (For help on parse errors, see splint -help parseerrors.)
*** Cannot continue.
army1987@army1987-laptop:~$
(There are more serious bugs, for example, given:
unsigned wager;
/* ... */
printf("%g\n", wager / 2.0);
It complains that the second argument of printf has type unsigned
instead of double...)

--
Army1987 (Replace "NOSPAM" with "email")
"Never attribute to malice that which can be adequately explained
by stupidity." -- R. J. Hanlon (?)

Aug 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wang Zangkun | last post by:
I knew SPLint for checking C source. Is there a similar (free) tool for C++ ? I'd like to find one which can check common problems (like if (i = 5)), and c++ stuffs like destructions of...
0
by: Greg Roberts | last post by:
I was trying to use splint under Visual Studio VC6 and it is giving parsing errors on windows system .h files (so far). Anyone know of a switch option to ignore these .h or make splint work ? ...
9
by: Henry Fr?d?ric | last post by:
I am currently working in Aisin-AW, in development of navigation systems (embedded SW). Since a few weeks, we are checking our source code with splint. We encounter this problem. I hope this...
3
by: ITP | last post by:
Hello, I'm seeing this with the ADO.NET SQLClient provider: When I check the connection's open status after it has been opened AND has been broken (I simulate this by disconnecting the cable...
1
by: arcliber | last post by:
I have download the splint-3.1.1 but i donnot know how to use and configure it could someone do me a favor, thx.
12
by: spibou | last post by:
I have two identical files , u1.c and u2.c which only contain the line typedef int Q ; When I issue "splint u1.c u2.c" I get u2.c:1:13: Datatype Q defined more than once A function or variable...
2
by: Peter Bencsik | last post by:
Hi, does anybody has experience with static source code checker for C? I am thinking of choosing splint as my favorite tool, is this a good choice? regards, pb
6
by: llothar | last post by:
While 90% of my application is written in Eiffel i have a few modules that are in C and i'm still gettings crashs from time to time. Not sure where it comes from but i thought about using lint as...
1
by: one2001boy | last post by:
Hello, gnu g++ offers something similar to lint/splint for statically checking C programs with the following command: g++ -W -Wall -Wshadow -Wwrite-strings -Wold-style-cast -Woverloaded-virtual...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.