Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <87cyolzqb2.fsf@bsb.me.uk>
Deutsch   English   Français   Italiano  
<87cyolzqb2.fsf@bsb.me.uk>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ben Bacarisse <ben@bsb.me.uk>
Newsgroups: comp.lang.c
Subject: Re: "stack smashing detected"
Date: Thu, 13 Jun 2024 00:36:49 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <87cyolzqb2.fsf@bsb.me.uk>
References: <666a10d3$0$973$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 13 Jun 2024 01:36:49 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f081befcc253f0e66a7d8b4dfbce31ac";
	logging-data="1987202"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/SlGadUqIStyjBEEl5IC+rhua492fK42c="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:7HqgITFb2osOAaO9YXqpdLz22j8=
	sha1:YDZAPedG+tVMKxonRXykMgLe88k=
X-BSB-Auth: 1.c4aa9f346b6651beedb4.20240613003649BST.87cyolzqb2.fsf@bsb.me.uk
Bytes: 2588

DFS <nospam@dfs.com> writes:

> Same C program I just made a post about 'undefined behavior' on.
>
> I just noticed I get "stack smashing detected" only when I run the program
> using a dataset of 75+ consecutive integers.
>
> set of 2 to 74 consecutive values: no problem.
> set of random values of any size: no problem.
> 75+ consecutive values: problem
>
> Any easy way to find out what's causing this issue (probably a buffer
> overflow)?

I compiled using -fsanitize=undefined and at runtime I get:

$ ./dfs 70 -c
70 Consecutive:
No commas     : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 
dfs.c:126:18: runtime error: index 70 out of bounds for type 'int [*]'
....

Line 126:

  if(nums[i]-nums[i+1]!=0) {ucnt=1;} else {ucnt++;}

nums is a VLA declared int nums[N]; and i runs from 0 to i < N (70 in
this run).  When i == 69 (the max) nums[i+1] is undefined (it's out of
bounds).

If I run

$ ./dfs 1 -c
1 Consecutive:
No commas     : 1 
dfs.c:126:18: runtime error: index 1 out of bounds for type 'int [*]'
dfs.c:161:14: runtime error: index -1 out of bounds for type 'int [*]'
dfs.c:162:32: runtime error: index 1 out of bounds for type 'int [*]'

I see two further problems.  With some stats you will have to set a
minimum for N, but the first problem is just an incorrect index.

BTW, when I was starting out, I'd give my right arm for gcc's
-fsanitize=undefined and/or valgrind.

-- 
Ben.