2

I have the following lines:

char *name = malloc(strsize + 1);

and

uint8_t *data;
data = (uint8_t *)name;

It is correct? It doesn't exist a chance that the pointer *name will be interpreted bad when that conversion is done?

  • Possible duplicate of [Conversion between uint8 and char in C](http://stackoverflow.com/questions/35264923/conversion-between-uint8-and-char-in-c) – gsamaras Oct 08 '16 at 10:50
  • Out of interest, why don't you malloc directly to uint8_t*? – Bathsheba Oct 08 '16 at 11:19
  • because i need to find a HUGE exploit in a program which was wrote by someone (he says that there is an exploit) and i need to find it and i was wondering if this is. – Otniel-Bogdan Mercea Oct 08 '16 at 12:52

2 Answers2

1

That shouldn't be much of a problem, except that the signedness of the memory would be interpreted differently between access along data and name. In most of the practical platforms, the size of char and uint8_t in bits is the same.

tofro
  • 5,640
  • 14
  • 31
0

No, the conversion is legal. However, problems will arise when you try to print data, because you no longer have a char*. Other than that the casting is fully supported.

fornit
  • 79
  • 1
  • 11