I am trying figure out a simple way to fill argv[1]
with an extremely large string of input to see how much input my program can handle. Any ideas on the simplest way to do this?
-
This seems pointless, but you can look [here](https://stackoverflow.com/questions/5349718/how-can-i-repeat-a-character-in-bash) for suggetions on how to piece together a large value to pass to the program in the shell. – Blaze Sep 20 '19 at 13:34
-
`argv[1]`, in case you are designating the second parameter to the `main()` function, is operating system dependant. You have not specified neither the operating system, nor any sample code to be able to decide how to answer you. Voting to close. – Luis Colorado Sep 22 '19 at 13:53
2 Answers
If you are calling your program from a shell, you typically take the advantage of that.
For instance, for POSIX, something like:
./program `printf '%*s' 500 | tr ' ' x`
(Taken from Creating string of repeated characters in shell script)
You can also create the string dynamically over a loop to test the program until it crashes, etc.
If you want a C solution (without spawning another process, e.g. using something like system
or OS-specific APIs), I would suggest you rename your main()
into a different function, and then write a new main()
that calls the old one with an argv
customized however you like:
int old_main(int argc, char *argv[]) { ... }
int main()
{
int argc = 2;
char *argv[2] = {
"program",
"xxxxxxxxxxxxxxxxxxxxxxx",
};
return old_main(argc, argv);
}

- 24,970
- 5
- 40
- 69
If you're using a POSIX shell (Like Bash on Linux or similar) then you could use a simply Python script to "fill" an argument, and call it using the shell back-tick to execute commands "inline":
./your_program `python -c "print('A'*100)"`
The above will create a string of 100 A
characters as the first argument to the program.

- 400,186
- 35
- 402
- 621