-3

I have very weird problem. I'm doing performance testing in LoadRunner and noticed that in some addresses I have weirdly coded characters.

I wrote a test app, this is the code:

char bla[256]="test %3A test %2B"; 
printf(bla);

The output has no sense. It looks like this:

test 0X0.000000P+0 test B

What is going on here?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Paweł Reszka
  • 1,557
  • 4
  • 20
  • 41

1 Answers1

2

I think, the problem here is caused by the presence of the %-ed elements like %3A and %2B in the array, and you're passing that to printf() as the only argument, without a format specifier string in place.

When you pass a string directly to printf() (as the first argument to printf()), it interprets those as format specifiers, and expect argument for that. But using

  • invalid format specifier %2B and
  • supplying less arguments (in this case, should be ideally two)

are both undefined behaviour.

You can try changing you print statement to

 printf("%s\n", bla);

to make the printf() understand that those %s does not carry any special meaning, they are simply to be printed.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • Thanks for help! I haven't been programming in C for few years, now it looks REALLY different after using almost exclusively C# and JS :P – Paweł Reszka Jun 30 '15 at 08:15