- void* pvTmp;
- if ((pvTmp = GlobalReAlloc(p, s, 0)) == NULL) {
- if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
- CopyMemory(pvTmp, p, GlobalSize(p));
- GlobalFree(p);
- }
- }
- return ((tdata_t)pvTmp);
+ void* pvTmp;
+ tsize_t old=GlobalSize(p);
+ if (old>=s)
+ {
+ if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
+ CopyMemory(pvTmp, p, s);
+ GlobalFree(p);
+ }
+ }
+ else
+ {
+ if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
+ CopyMemory(pvTmp, p, old);
+ GlobalFree(p);
+ }
+ }
+ return ((tdata_t)pvTmp);