I decompiled a application and I don't know the real array size so I made it pretty big but I wonder do I need to make exactly what I know it's going to be before the strcpy
is used or must I consider the size of the strcpy
as well?
signed int __cdecl SendSomePacket(struct CONNECTION* conn, int a1, int a2, const char *a3)
{
//char buf[256]; // [sp+10h] [bp-9h]@1
char buf[10]; // [sp+10h] [bp-9h]@1
*(unsigned int *)&buf[1] = a1;
*(unsigned int *)&buf[5] = a2;
strcpy(&buf[9], a3);
buf[0] = 0xEu; // Packet Type
return SendPacket(CONNECTION->socket, buf, strlen(a3) + 10, 1);
}
I ask should I leave it with 256 which is the default size it guesses by which is always multiplies of 2 like 256,512,1024,2048..
char buf[256]; // [sp+10h] [bp-9h]@1
or should I make it as small as possible to save memory.
char buf[10]; // [sp+10h] [bp-9h]@1
which I figured after the strlen(a3)
that number is how big the buffer should be.
I tried just strcpy with a buffer size of 10.. and I put in a string thats over 500 in length and it worked maybe just got lucky. I just wanted to know should I make the static buffer large enough for the initial packet + the data from the strcpy or just for the packet alone? and the packet gets appended probably anyways.
Here is a example I tried.