N
Noob
Hello,
I suppose the following code has undefined behavior?
#include <string.h>
#include <assert.h>
typedef unsigned long ULONG;
struct msg
{
ULONG event;
ULONG args[4];
};
void dispatch_msg(ULONG *argv, int argc)
{
struct msg foob;
assert(0 <= argc && argc <= 5);
memcpy(&foob, argv, argc * sizeof *argv); /*** UB here ?? ***/
/* send foob to the handler */
}
I imagine a (nasty ;-) compiler implementation could insert
padding between event and args in struct msg, making
sizeof(struct msg) > sizeof(ULONG[5])
thereby giving the memcpy undefined behavior?
Regards.
I suppose the following code has undefined behavior?
#include <string.h>
#include <assert.h>
typedef unsigned long ULONG;
struct msg
{
ULONG event;
ULONG args[4];
};
void dispatch_msg(ULONG *argv, int argc)
{
struct msg foob;
assert(0 <= argc && argc <= 5);
memcpy(&foob, argv, argc * sizeof *argv); /*** UB here ?? ***/
/* send foob to the handler */
}
I imagine a (nasty ;-) compiler implementation could insert
padding between event and args in struct msg, making
sizeof(struct msg) > sizeof(ULONG[5])
thereby giving the memcpy undefined behavior?
Regards.