/* 
 * 1. Definitions to satisfy the compiler 
 */
#define NULL ((void *)0)

/* Match the exact signature from your error log: unsigned int */
void *__coverity_alloc__(unsigned int);
void __coverity_free__(void *);

/* 2. Wireshark Type Definitions */
typedef struct _wmem_allocator_t {
    void *storage_sink; 
} wmem_allocator_t;

typedef struct _packet_info {
    wmem_allocator_t *pool;
} packet_info;

/* 3. Allocation Logic */
/* We use unsigned int for the size argument to remain compatible with the primitive above */
void *wmem_alloc(wmem_allocator_t *allocator, unsigned int size) {
    void *ptr = __coverity_alloc__(size);
    if (allocator != NULL) {
        /* Scoped: Escape to sink so Coverity doesn't expect a free() here */
        allocator->storage_sink = ptr;
    }
    return ptr;
}

/* 4. Deallocation Logic */
void wmem_free(wmem_allocator_t *allocator, void *ptr) {
    if (allocator == NULL) {
        __coverity_free__(ptr);
    }
}

/* 5. String and Memory Utilities */
char *wmem_strdup(wmem_allocator_t *allocator, const char *src) {
    return (char *)wmem_alloc(allocator, 1);
}

void *wmem_memdup(wmem_allocator_t *allocator, const void *source, const unsigned int size) {
    return wmem_alloc(allocator, size);
}

char *wmem_strconcat(wmem_allocator_t *allocator, const char *first, ...) {
    return (char *)wmem_alloc(allocator, 1);
}

/* 6. Scopes */
static wmem_allocator_t *epan_scope_ptr;
static wmem_allocator_t *file_scope_ptr;

wmem_allocator_t *wmem_epan_scope(void) {
    if (!epan_scope_ptr) {
        /* Using a dummy size for the allocator struct itself */
        epan_scope_ptr = (wmem_allocator_t*)__coverity_alloc__(16);
    }
    return epan_scope_ptr;
}

wmem_allocator_t *wmem_file_scope(void) {
    if (!file_scope_ptr) {
        file_scope_ptr = (wmem_allocator_t*)__coverity_alloc__(16);
    }
    return file_scope_ptr;
}
