Whether you want to use alloca/VLA or whether you want to used a fixed buffer (that may be too small) depends on what you expect to happen at runtime and how you want to deal with the error conditions.
For example, with the fixed buffer, if the incoming message is too big, you might just copy the portion that fits into your buffer. You don't get the whole message, but you don't get a crash.
With alloca, if the message is very large, alloca itself will fail and you'll get a null pointer to work with. If you don't check the return value and try to use it, you'll have an instant crash (if you're lucky). On the other hand, if you do check the return value, you have to decide what course of action to take. Punt? Notify the user, etc?Actually, reading the man page for alloca, it's even worse than that. Alloca actually just gives you a pointer to an extended stack frame. If the stack frame cannot be extended to the requested size, you don't even get a null return value to check. You get undefined behavior. That is, it seems you cannot even theoretically write a correct program this way. And, again, in the embedded world where you are often working with threads with microscopic stacks, this is not very theoretical.
Memory management is unpleasant, tedious work. Embedded systems with very limited resources and external inputs that can very in size without restrictions do not make a happy marriage.
in C99 you can use variable-length arrays (VLAs). So instead of declaring your char message[] in global scope, you could declare it inside a function.
int main() {
char message[strlen(MSG)+1];
strcpy(message,MSG);
....
}
This would let you make a buffer of whatever size is needed to hold the data that's currently in EEPROM. You can also use alloca() in compilers that don't support C99:
int main() {
char *message=(char *) alloca(strlen(MSG)+1);
if (message!=0) strcpy(message,MSG);
.....
}
The way you have written it with memcpy and sizeof, however, doesn't permit the size to change at runtime: that length is fixed by the source code.