|
From: aruperez <arm...@gm...> - 2008-08-19 18:58:43
|
I'm using valgrind a in'm having a little problem, I'm using the function sprintf to convert an int to a char * if you check the example how to use this function in www.cppreference.com there is something like this char result[100]; int num = 24; sprintf( result, "%d", num ); however when i do that in my code, valgrind reports the following error ==16490== Use of uninitialised value of size 4 ==16490== at 0x43876E4: __printf_fp (in /lib/libc-2.6.1.so) ==16490== by 0x4382FE0: vfprintf (in /lib/libc-2.6.1.so) ==16490== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) ==16490== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) what should i do?? initialize the char[] before calling the function?, which is the best way to do it becuase i tried assigning = "" but valgrind still complained. thanks for your help. AR -- View this message in context: http://www.nabble.com/Initialize-a-char---to-use-sprintf-function-tp19056515p19056515.html Sent from the Valgrind - Users mailing list archive at Nabble.com. |
|
From: Christoph B. <bar...@or...> - 2008-08-19 22:20:44
|
Am Dienstag, 19. August 2008 schrieb aruperez: > I'm using valgrind a in'm having a little problem, > > I'm using the function sprintf to convert an int to a char * > if you check the example how to use this function in www.cppreference.com > > there is something like this > char result[100]; > int num = 24; > sprintf( result, "%d", num ); > > however when i do that in my code, valgrind reports the following error > ==16490== Use of uninitialised value of size 4 > ==16490== at 0x43876E4: __printf_fp (in /lib/libc-2.6.1.so) > ==16490== by 0x4382FE0: vfprintf (in /lib/libc-2.6.1.so) > ==16490== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) > ==16490== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) > > what should i do?? initialize the char[] before calling the function?, > which is the best way to do it becuase i tried assigning = "" but valgrind > still complained. Your example code looks ok. Show us the real code. Christoph |
|
From: aruperez <arm...@gm...> - 2008-08-19 22:51:00
|
Christoph Bartoschek-2 wrote: > > > Your example code looks ok. Show us the real code. > > Christoph > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the > world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users > > Well is very much the same but here it is string packSerial(int denomNumber, int cluster, int lot, int sublot, int serial){ char ser[11]; string container; string lotN = string(); sprintf(ser,"%d",denomNumber); container = string(ser); lotN.append(container.c_str()); sprintf(ser,"%d",cluster); container = string(ser); while(container.length()<3){ container = string('0'+container); } lotN.append(container.c_str()); sprintf(ser,"%d",lot); container = string(ser); while(container.length()<5){ container = string('0'+container); } for every one of the sprintf calls valgrind says Conditional jump or move depends on uninitialised value(s) ==28593== at 0x43820E5: vfprintf (in /lib/libc-2.6.1.so) ==28593== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) ==28593== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) ==28593== by 0x806D42E: card_manager::packSerial(int, int, int, int, int) (card_manager.cpp:431) ==28593== by 0x807396B: card_manager::gen_keys(int, int, int, int, std::string) (card_manager.cpp:280) ==28593== by 0x8076BE2: command_interpreter::interpret(iso8583_frame const&) (command_interpreter.cpp:126) ==28593== by 0x8078642: request_handler::con_handling(request) (request_handler.cpp:55) ==28593== by 0x80787AE: request_handler::handle(request) (request_handler.cpp:25) ==28593== by 0x807888F: queue_process::consume(void*) (queue_process.cpp:69) ==28593== by 0x805CBAF: Consume(void*) (queue_process.cpp:78) ==28593== by 0x41CA191: start_thread (in /lib/libpthread-2.6.1.so) ==28593== by 0x440802D: clone (in /lib/libc-2.6.1.so) thanks for any help -- View this message in context: http://www.nabble.com/Initialize-a-char---to-use-sprintf-function-tp19056515p19060205.html Sent from the Valgrind - Users mailing list archive at Nabble.com. |
|
From: Kevin N. <kev...@or...> - 2008-08-20 00:00:27
|
A few thoughts:
1. maybe when you call this function, you are passing uninitialized
values for the int parameters?
2. this apparently is not the whole function, since there is no end
brace, and since you don't do anything with lotN or the last value of
container
3. this could sure be a lot easier using C's sprintf, and almost
certainly using C++ strings
using sprintf:
char ser[10*3+1];
sprintf(ser, "%d%03d%05d", denomNumber, cluster, lot);
aruperez wrote:
>
> Christoph Bartoschek-2 wrote:
>
>> Your example code looks ok. Show us the real code.
>>
>> Christoph
>>
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Valgrind-users mailing list
>> Val...@li...
>> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>>
>>
>>
>
> Well is very much the same but here it is
>
> string packSerial(int denomNumber, int cluster, int lot, int sublot, int
> serial){
>
> char ser[11];
>
> string container;
>
> string lotN = string();
>
>
>
> sprintf(ser,"%d",denomNumber);
>
> container = string(ser);
>
> lotN.append(container.c_str());
>
> sprintf(ser,"%d",cluster);
>
> container = string(ser);
>
> while(container.length()<3){
>
> container = string('0'+container);
>
> }
>
> lotN.append(container.c_str());
>
> sprintf(ser,"%d",lot);
>
> container = string(ser);
>
> while(container.length()<5){
>
> container = string('0'+container);
>
> }
>
> for every one of the sprintf calls valgrind says
>
> Conditional jump or move depends on uninitialised value(s)
> ==28593== at 0x43820E5: vfprintf (in /lib/libc-2.6.1.so)
> ==28593== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so)
> ==28593== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so)
> ==28593== by 0x806D42E: card_manager::packSerial(int, int, int, int, int)
> (card_manager.cpp:431)
> ==28593== by 0x807396B: card_manager::gen_keys(int, int, int, int,
> std::string) (card_manager.cpp:280)
> ==28593== by 0x8076BE2: command_interpreter::interpret(iso8583_frame
> const&) (command_interpreter.cpp:126)
> ==28593== by 0x8078642: request_handler::con_handling(request)
> (request_handler.cpp:55)
> ==28593== by 0x80787AE: request_handler::handle(request)
> (request_handler.cpp:25)
> ==28593== by 0x807888F: queue_process::consume(void*)
> (queue_process.cpp:69)
> ==28593== by 0x805CBAF: Consume(void*) (queue_process.cpp:78)
> ==28593== by 0x41CA191: start_thread (in /lib/libpthread-2.6.1.so)
> ==28593== by 0x440802D: clone (in /lib/libc-2.6.1.so)
>
>
> thanks for any help
>
>
>
>
|
|
From: Steve F. <sf...@re...> - 2008-08-20 21:46:26
|
Kevin Neel wrote: >> Conditional jump or move depends on uninitialised value(s) >> ==28593== at 0x43820E5: vfprintf (in /lib/libc-2.6.1.so) >> ==28593== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) >> ==28593== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) >> ==28593== by 0x806D42E: card_manager::packSerial(int, int, int, int, int) >> (card_manager.cpp:431) >> ==28593== by 0x807396B: card_manager::gen_keys(int, int, int, int, >> std::string) (card_manager.cpp:280) >> ==28593== by 0x8076BE2: command_interpreter::interpret(iso8583_frame >> const&) (command_interpreter.cpp:126) Staring at that stack trace, I wonder if it would be possible to have it include the initialization status of the arguments. Something like: ==28593== by 0x806D42E: card_manager::packSerial(int, UNINITIALIZED int, int, UNINITIALIZED int, int) (card_manager.cpp:431) I know it doesn't help in all cases -- some of those arguments might not be used, so the 'UNINITIALIZED' tag might lead you astray. And perhaps much of the time the uninitialized data is reached through a pointer argument, which would itself be initialized and so not get flagged, but I still wonder if this might be helpful in a fair percentage of cases. This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited. |
|
From: Bart V. A. <bar...@gm...> - 2008-08-20 06:22:52
|
On Wed, Aug 20, 2008 at 12:51 AM, aruperez <arm...@gm...> wrote: > sprintf(ser,"%d",denomNumber); > container = string(ser); > lotN.append(container.c_str()); Please look up the documentation of class std::ostringstream in a book about C++ or the STL -- you can implement the above a lot easier and more efficiently with streams than with string concatenation. Bart. |
|
From: Julian S. <js...@ac...> - 2008-08-20 07:16:05
|
> for every one of the sprintf calls valgrind says > > Conditional jump or move depends on uninitialised value(s) > ==28593== at 0x43820E5: vfprintf (in /lib/libc-2.6.1.so) > ==28593== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) > ==28593== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) > [...] > thanks for any help Check out and build the SVN trunk valgrind, as described at http://valgrind.org/downloads/repository.html Then run the new Valgrind with --track-origins=yes. This will tell you where the uninitialised data is coming from. J |
|
From: Guilherme M. <gui...@gm...> - 2008-08-22 02:04:26
|
Have you tried: bzero(result, 100); ?? 2008/8/19 aruperez <arm...@gm...> > > I'm using valgrind a in'm having a little problem, > > I'm using the function sprintf to convert an int to a char * > if you check the example how to use this function in www.cppreference.com > > there is something like this > char result[100]; > int num = 24; > sprintf( result, "%d", num ); > > however when i do that in my code, valgrind reports the following error > ==16490== Use of uninitialised value of size 4 > ==16490== at 0x43876E4: __printf_fp (in /lib/libc-2.6.1.so) > ==16490== by 0x4382FE0: vfprintf (in /lib/libc-2.6.1.so) > ==16490== by 0x439E91B: vsprintf (in /lib/libc-2.6.1.so) > ==16490== by 0x438A42D: sprintf (in /lib/libc-2.6.1.so) > > what should i do?? initialize the char[] before calling the function?, > which > is the best way to do it becuase i tried assigning = "" but valgrind still > complained. > > thanks for your help. > > AR > > -- > View this message in context: > http://www.nabble.com/Initialize-a-char---to-use-sprintf-function-tp19056515p19056515.html > Sent from the Valgrind - Users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users > -- Guilherme Müller Master Solve Indústria Mecatrônica Ltda CNPJ: 05.916.813/0001-40 Rua Washington Luiz, 675 - Prédio 1 - Sala 1116/1117 Porto Alegre - RS - CEP 90010-460 Fone: 55 - 51 3287 - 2150 Fax: 55 - 51 32872092 gui...@gm... MSN: gm...@ma... Skype: gmuller.mastersolve www.mastersolve.com.br |