473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why does this dump core?

What's wrong with this code?

#define DEBUG 1
#include <string.h>
#if DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#define MAX_LEN 32767
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {
strncat(line, " ", MAX_LEN - len - 1);
len++;
strncat(line, *argv, MAX_LEN - len - 1);
len += strlen(*argv);
}
#if DEBUG
puts(line);
return 0;
#endif
return system(line);
}
--
char s[]="\16Jsa ukenethr ,cto haCr\n";int main(void){*s*=5;*
s%=23;putchar(s[0][s]);return*s-14?main():!putchar(9[s+*s]);}
May 12 '07 #1
7 1376
On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
>What's wrong with this code?

#define DEBUG 1
#include <string.h>
#if DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#define MAX_LEN 32767
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {
You need to test *argv for NULL.
strncat(line, " ", MAX_LEN - len - 1);
len++;
strncat(line, *argv, MAX_LEN - len - 1);
len += strlen(*argv);
}
#if DEBUG
puts(line);
return 0;
#endif
return system(line);
}

Remove del for email
May 12 '07 #2

"Barry Schwarz" <sc******@doezl.netha scritto nel messaggio
news:6j********************************@4ax.com...
On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
>>What's wrong with this code?

#define DEBUG 1
#include <string.h>
#if DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#define MAX_LEN 32767
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {

You need to test *argv for NULL.
Yes. I replaced it with while (*++argv && len < MAX_LEN) and it
works. Of course argv itself will never become NULL. I wonder how
could I repeatedly fail to see that. I had even suspected that forù
some reasons one cannot assign to argv...
May 12 '07 #3
Barry Schwarz wrote:
>
On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
What's wrong with this code?
[...]
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {

You need to test *argv for NULL.
[...]

Does the standard guarantee that argv[argc]==NULL (I know that the
implementations I use do add a NULL to the argv[] array), or do you
need to make sure you stop at argv[argc-1] ?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

May 14 '07 #4
Kenneth Brody wrote:
Barry Schwarz wrote:

On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
What's wrong with this code?
[...]
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {
You need to test *argv for NULL.
[...]

Does the standard guarantee that argv[argc]==NULL
Yes. From the c99 draft:

[#2] If they are declared, the parameters to the main
function shall obey the following constraints:

-- The value of argc shall be nonnegative.

-- argv[argc] shall be a null pointer.
Brian
May 14 '07 #5
Op Mon, 14 May 2007 13:41:47 -0400 schreef Kenneth Brody:
Barry Schwarz wrote:
>>
On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
>>>What's wrong with this code?
[...]
>>>int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {

You need to test *argv for NULL.
[...]

Does the standard guarantee that argv[argc]==NULL (I know that the
implementations I use do add a NULL to the argv[] array), or do you
need to make sure you stop at argv[argc-1] ?
Yes, n1124.pdf, paragraph 5.1.2.2.1 Program startup states
¡X argv[argc] shall be a null pointer.

--
Coos
May 14 '07 #6

"Army1987" <pl********@for.itwrote in message
news:f2**********@tdi.cu.mi.it...
>
"Barry Schwarz" <sc******@doezl.netha scritto nel messaggio
news:6j********************************@4ax.com...
>On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:
>>>What's wrong with this code?

#define DEBUG 1
#include <string.h>
#if DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#define MAX_LEN 32767
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {

You need to test *argv for NULL.

Yes. I replaced it with while (*++argv && len < MAX_LEN) and it
works.
No, it doesn't. You are not checking whether argv is NULL.
Youi are incrementing it and THEN checking for NULL.
Of course argv itself will never become NULL.
Sure it can. One way is this:

int main( int argc, char **argv ) {
if ( argv!=NULL) {
main(0, NULL);
}
return 0;
}
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing
May 14 '07 #7

"Fred Kleinschmidt" <fr******************@boeing.comha scritto nel
messaggio news:JI********@news.boeing.com...
>
"Army1987" <pl********@for.itwrote in message
news:f2**********@tdi.cu.mi.it...
>>
"Barry Schwarz" <sc******@doezl.netha scritto nel messaggio
news:6j********************************@4ax.com.. .
>>On Sat, 12 May 2007 01:58:38 +0200, "Army1987" <pl********@for.it>
wrote:

What's wrong with this code?

#define DEBUG 1
#include <string.h>
#if DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#define MAX_LEN 32767
int main(int argc, char **argv)
{
char line[MAX_LEN] = "gcc -ansi -pedantic -Wall -Wextra -O3";
size_t len = strlen(line);
while (++argv && len < MAX_LEN) {

You need to test *argv for NULL.

Yes. I replaced it with while (*++argv && len < MAX_LEN) and it
works.
No, it doesn't. You are not checking whether argv is NULL.
Youi are incrementing it and THEN checking for NULL.
So? argv looks like this:

argv
\/
|ptr. to program name|ptr. to 1st arg|...|ptr. to last arg|NULL|
After ptr. to last argument has been used, argv is increased, then
checked for NULL. Since it is NULL, the loop breaks. This is
exactly what I was trying to do.
May 24 '07 #8

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

Similar topics

2
by: Ng Pheng Siong | last post by:
Hi, I just noticed that demo/evp_ciph_test.py of my M2Crypto package causes a core dump. It used to not do that. ;-) The core dump happens when the program is exiting; in the output below,...
6
by: pit3k | last post by:
My program tries to call the vector::push_back(...) member function in a loop couple dozen milion times, which is what I expect. After about 20 millions successfull push_back() calls the program...
6
by: John Liu | last post by:
I've two questions, they may or may not be related - 1. I copied the entire data directory from postgreSQL 7.3.2 (AIX4.3) to the installation postgreSQL 7.3.4 (AIX5.1), the same filesystem setup....
3
by: John Liu | last post by:
AIX pg version 7.4 Select * from document2 core dump. Did a few more experiments with select * from document2 limit... I limit to 500000 it works, 600000 it exits but says "calloc:...
5
by: johnericaturnbull | last post by:
Hi - I am very new to python. I get this random core dump and am looking for a good way to catch the error. I know the function my core dump occurs. Is there any error catching/handling that I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.