sprintf

why doesnt this segfault

hello all I stumbled across something "interesting" and I cant put my finger why the behaviour isn't coherent. Check this code. char buf[100]; sprint(buf,"%s",bla); Simple, right. It's easy to understand what is going on when bla is a NULL pointer. This should always segfault right!? In one machine the executable segfaults, on ano...

Strange SIGABRT error.

Hi, I was trying to make a program but, when add sprintf to the equation, I get the following error: Program received signal: "SIGABRT" My sprintf is written as follows: int i; int g; char b[6]; sprintf(b, "%d", i*g); If you need to see the whole code here it is (but you probably don't, just in case though): #include <stdio.h>...

Consequences of this buffer overflow?

So here I believe I have a small buffer overflow problem I found when reviewing someone else's code. It immediately struck me as incorrect, and potentially dangerous, but admittedly I couldn't explain the ACTUAL consequences of this "mistake", if any. I had written up a test app to demonstrate the error, but found (to my dismay) that it...

Problem with sprintf error when using S3->copyObject() and filenames with % in them.

I am using PHP S3.PHP class to manage files on Amazon S3. I use the copyObject() function to copy files in my S3 bucket. All works great until I meet filenames that need to be urlencoded (I urlencode everything anyway). When a filename ends up with % characters in it the copyObject() function spits the dummy. for example - the filename...

Is it possible to use the sprintf() function in XSLT?

I'd like to do something like "Hello %s" and have "World" in another variable. Of course I could do this simple case using string replacement but if possible I'd like all sprintf() features like argument reordering, which would be very complex to do myself. ...

How to format unsigned int into 8 digit hexadecimal number?

I want to format an unsigned int to an 8 digit long string with leading zeroes. This is what I have so far: unsigned int number = 260291273; char output[9]; sprintf(output, "%x", number); printf("%s\n", output); // or write it into a file with fputs Prints "f83bac9", but I want "0f83bac9". How can I achieve the formatting? ...

Help with sprintf function in R.

Hi All, I have the following R code: df <- xmlToDataFrame(/Users/usr/Desktop/shares.xml) df$timeStamp <- strptime(as.character(df$XTimeStamp), "%H:%M:%OS") df$SharePrice <- as.numeric(as.character(df$SharePrice)) sapply(df, class) options("digits.secs"=3) diff <- diff(df$SharePrice) diff sink (file="c:/xampp/htdocs/data.xml", type="out...

Clojure sprintf?

There is printf. It prints directly to stdout. How about sprintf, which formats the same way as printf, but returns a string with no side-effects? ...

sprintf fails spontaneously depending on what printf and NSLog calls there are.

Hello I have a bizarre problem with sprintf. Here's my code: void draw_number(int number,int height,int xpos,int ypos){ char string_buffer[5]; //5000 is the maximum score, hence 4 characters plus null character equals 5 printf("Number - %i\n",number); sprintf(string_buffer,"%i",number); //Get string printf("String - %s\n...

How to use asprintf with the Boehm GC?

As far as I can tell, asprintf calls malloc. If I replace malloc with the Boehm GC, a call to asprintf still calls the traditional malloc - at least that's what valgrind is telling me: Here's the malloc macro: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdbool.h> #include <gc.h> #define malloc(n) GC_MALLO...

c++ - understanding the dangers of sprintf(...)

OWASP says: "C library functions such as strcpy (), strcat (), sprintf () and vsprintf () operate on null terminated strings and perform no bounds checking." sprintf writes formatted data to string int sprintf ( char * str, const char * format, ... ); Example: sprintf(str, "%s", message); // assume declaration and ...

How do I convert this code to c++?

I have this code: string get_md5sum(unsigned char* md) { char buf[MD5_DIGEST_LENGTH + MD5_DIGEST_LENGTH]; char *bptr; bptr = buf; for(int i = 0; i < MD5_DIGEST_LENGTH; i++) { bptr += sprintf(bptr, "%02x", md[i]); } bptr += '\0'; string x(buf); return x; ...

Are printf/sprintf compiler warnings a conceptual break?

I have noticed that a large number of C compilers issue warnings when the conversion specifiers in the format string of the printf/sprintf functions do not match the type or the count of the corresponding arguments. That seems to me like a conceptual break since C doesn't have built-in functions according to the language specification. ...

sprintf, commas and dots in C(++) (and localization?)

I am working in a project using openframeworks and I've been having some problems lately when writing XMLs. I've traced down the problem to a sprintf: It seems that under certain conditions an sprintf call may write commas instead of dots on float numbers (e.g. "2,56" instead of "2.56"). In my locale the floating numbers are represented...

PHP: Can you use an array as the arguments part of the sprintf function? if so - how?

From the PHP API reference: string sprintf ( string $format [, mixed $args [, mixed $... ]] ) Returns a string produced according to the formatting string format. Can $args be an array - If so how would I use it? ...

sprintf() with automatic memory allocation?

Hello! I'm searching for a sprintf()-like implementation of a function that automatically allocates required memory. So I want to say char* my_str = dynamic_sprintf( "Hello %s, this is a %.*s nice %05d string", a, b, c, d ); and my_str retrieves the adress of an allocated memory that holds the result of this sprintf(). In another fo...

sprintf warning - encoding issue

I'm using the following code to find all properties for a user and in turn delete them. My problem is that I'm getting a warning: Warning: sprintf(): Too few arguments for each of the properties. However, when I manually enter the $user_id for the delete string as first_last%%40ourwiki.com it works! Seems like sprintf requires double ...

MySQL LIKE + php sprintf

$test = sprintf("SELECT * FROM `table` WHERE `text` LIKE '%%s%'", mysql_real_escape_string('test')); echo $test; output: SELECT * FROM `table` WHERE `text` LIKE '%s but it should output: SELECT * FROM `table` WHERE `text` LIKE '%test%' ...

In Perl, how can I do 64bit hex/decimal arithmetic AND output full number in HEX as string?

I need to do some arithmetic with large hexadecimal numbers below, but when I try to output I'm getting overflow error messages "Hexadecimal number > 0xffffffff non-portable", messages about not portable, or the maximum 32bit hex value FFFFFFFF. All of which imply that the standard language and output routines only cope with 32 bit value...

C : sprintf inside printf as first argument

Learning C at University. This is not a homework, but I was trying to do something (some "creative" part of the assignment) and got stuck. I understand that this is possible printf("%d\n", printf("23.4")); // -> 23.44 (i.e. 23.4 + 4 bytes written) but how can I use sprintf() as first argument of printf() ? something like : char * g...