0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-11-08 23:27:15 -05:00
Files
nasm/asm/uncompress.c
H. Peter Anvin (Intel) acfeb7df6c zlib: pass 15 not 0 to inflateInit2()
The convention of passing 0 to inflateInit2() to autodetect the window
size is not supported in really old versions of zlib. The only
downside with simply passing in the maximum value (15) is potential
additional memory buffer allocations, but it is a drop in the bucket
for NASM.

Fixes: https://github.com/netwide-assembler/nasm/issues/165
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-11-04 00:38:17 -08:00

52 lines
1.1 KiB
C

/* SPDX-License-Identifier: BSD-2-Clause */
/* Copyright 2025 The NASM Authors - All Rights Reserved */
/*
* This needs to be in a separate file because zlib.h conflicts
* with opflags.h.
*/
#include "compiler.h"
#include "zlib.h"
#include "macros.h"
#include "nasmlib.h"
#include "error.h"
/*
* read line from standard macros set,
* if there no more left -- return NULL
*/
static void *nasm_z_alloc(void *opaque, unsigned int items, unsigned int size)
{
(void)opaque;
return nasm_calloc(items, size);
}
static void nasm_z_free(void *opaque, void *ptr)
{
(void)opaque;
nasm_free(ptr);
}
char *uncompress_stdmac(macros_t *sm)
{
z_stream zs;
void *buf = nasm_malloc(sm->dsize);
nasm_zero(zs);
zs.next_in = (void *)sm->zdata;
zs.avail_in = sm->zsize;
zs.next_out = buf;
zs.avail_out = sm->dsize;
zs.zalloc = nasm_z_alloc;
zs.zfree = nasm_z_free;
if (inflateInit2(&zs, 15) != Z_OK)
panic();
if (inflate(&zs, Z_FINISH) != Z_STREAM_END)
panic();
inflateEnd(&zs);
return buf;
}