In libgdiplus-2.8, the following is dumb: unsigned long long int size; size = bmi.biWidth; size *= 4; if (size > G_MAXINT32) goto error; The following is a better way: long size; size = bmi.biWidth; if (size > G_MAXINT32 / 4) goto error; size *= 4;