* Copy an array of PGEvents (with no extra space for more). * Does not duplicate the event instance data, sets this to NULL. * Also, the resultInitialized flags are all cleared. * The total space allocated is added to *memSize. */
| 413 | * The total space allocated is added to *memSize. |
| 414 | */ |
| 415 | static PGEvent * |
| 416 | dupEvents(PGEvent *events, int count, size_t *memSize) |
| 417 | { |
| 418 | PGEvent *newEvents; |
| 419 | size_t msize; |
| 420 | int i; |
| 421 | |
| 422 | if (!events || count <= 0) |
| 423 | return NULL; |
| 424 | |
| 425 | msize = count * sizeof(PGEvent); |
| 426 | newEvents = (PGEvent *) malloc(msize); |
| 427 | if (!newEvents) |
| 428 | return NULL; |
| 429 | |
| 430 | for (i = 0; i < count; i++) |
| 431 | { |
| 432 | newEvents[i].proc = events[i].proc; |
| 433 | newEvents[i].passThrough = events[i].passThrough; |
| 434 | newEvents[i].data = NULL; |
| 435 | newEvents[i].resultInitialized = false; |
| 436 | newEvents[i].name = strdup(events[i].name); |
| 437 | if (!newEvents[i].name) |
| 438 | { |
| 439 | while (--i >= 0) |
| 440 | free(newEvents[i].name); |
| 441 | free(newEvents); |
| 442 | return NULL; |
| 443 | } |
| 444 | msize += strlen(events[i].name) + 1; |
| 445 | } |
| 446 | |
| 447 | *memSize += msize; |
| 448 | return newEvents; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | /* |
no outgoing calls
no test coverage detected