Detect sprintf and fprintf bad use


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Detect sprintf and fprintf bad use
# 1  
Old 02-22-2010
Detect sprintf and fprintf bad use

Hello again,

I don't know about regexp so I throw this question here:

How can I detect files where, for example:
Code:
sprintf (var1, "hello %s %s", sub1);

The problem here is that we have 2 %s and only a variable.

Or... the inverse:
Code:
sprintf (var1, "hello %s %s", sub1, sub2, sub3,...subn);

And...the sentences can be in more than one line:
Code:
sprintf (var1, 
"hello %s %s", 
sub1);

I know that this is not inmediate, I'll try a solution this afternoon, but if somebody can tell me a clue where I can start....


Thank you very much

Last edited by pludi; 02-22-2010 at 09:01 AM.. Reason: code tags, please...
# 2  
Old 02-22-2010
Do you have the gcc compiler for your platform?
Code:
gcc -Wall mycode.c -o mycode

will list any line and flag as a warning if there is a datatype mismatch between
the format string and the arguments to any of the printf() function family.
# 3  
Old 02-22-2010
Thank you,

yes I have cc instead of gcc but I have a lot of code (thousand of files) and we have changed the micro-processor so the compiler version too and now there is warnings that create problems in the execution.
I would like to obtain the problematic files without compile...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fprintf issue

i had to send a mail an attachment which i got from find command. But i did not get mail but could see the following line in the logs "aliased to fprintf.c". Can someone help me to understand what does it mean?..As this issue is not occuring now, i could not replicate the problem now.Thanks. (1 Reply)
Discussion started by: jesu
1 Replies

2. Programming

fprintf() gives segmentation fault

Hi, I am using fprintf to write few strings toa file which has been opened in write mode. The syntax is as follows: printf("Testing 7A.\n"); fprintf(out_screen,"%s|%s|%s|%s|%s|\n",var1,var2,var3,var4,var5); printf("Testing 8.\n"); When I execute the code It prints "Testing 7A." then... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

3. Programming

Problem with Sprintf

Hi, I have the below sample code to hash the input number read from file. File will have 16 to 19 digit number and executable hash the number using some logic and returns the hashed value. Each digit in the 16 digit number is converted to a 4 byte value. That if the input is 16digit integer, the... (6 Replies)
Discussion started by: ramkrix
6 Replies

4. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

5. Shell Programming and Scripting

sprintf result on perl

Hello, In perl lang, I have create a string (@str) by sprintf but unfortunately when program printed it out, only I could saw a number like 1. Certainly printf doesn't problem. How I can convert a string that are result of sprintf to a common string format??! Thanks in advance. PLEASE HELP ME. (2 Replies)
Discussion started by: Zaxon
2 Replies

6. Programming

fprintf

Could someone explain me the following fprintf format: fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); Why just not use: fprintf(stderr, "ry `%s --help' for more information.\n", program_name) I mean what is _() does? (1 Reply)
Discussion started by: mirusnet
1 Replies

7. Programming

equivalent of sprintf in C++

Hi My requirement is to convert the following to C++ char buffer; sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20)) Since the buffer is of varying length, i cannot hardcode the value as 90. i would like to convert the buffer to string object so that it can receive any... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

8. Shell Programming and Scripting

ksh scripting sprintf

is there any sprintf function in korn shell scripting, or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies

9. Programming

sprintf function

Hi, Can someone help me to figure out whether this code is to write file to /tmp/TIMECLOCK directory or just to asign a variable with "/tmp/TIMECLOCK/name.log_copy.pid" as the string? I am looking into an old C program and could not figure out where in the code that creates... (1 Reply)
Discussion started by: whatisthis
1 Replies

10. UNIX for Dummies Questions & Answers

how to write to file using fprintf in find command...

:D I once again am looking through the man pages and am still working on the find command to fully comprehend all its attributes.. i am a little stuck on a problem with how many options to -print there are and the only two I know how to use are printf and -print.. i can not make heads or tails of... (2 Replies)
Discussion started by: moxxx68
2 Replies
Login or Register to Ask a Question