• Paul Eggert's avatar
    Memory-management cleanup in make-docfile · 25ec995c
    Paul Eggert authored
    I compiled it with -fsanitize=address and fixed the leaks it detected.
    Also, I changed it to prefer signed to unsigned integer types,
    and to check for integer overflow.
    * lib-src/make-docfile.c:
    Include <stddef.h>, <stdint.h>, <intprops.h>, <min-max.h>.
    (memory_exhausted): New function.
    (xmalloc, xrealloc): Use it.
    (xmalloc, xrealloc, scan_file, struct rcsoc_state, write_c_args)
    (uncompiled, scan_lisp_file):
    Prefer signed integer types to unsigned.
    (xstrdup): Remove.  All uses removed.
    (num_globals, num_globals_allocated, write_globals, scan_c_stream):
    Use ptrdiff_t, not int, for indexes that in theory could exceed INT_MAX.
    (add_global): Use const to pacify --enable-gcc-warnings.
    Make a copy here, rather than relying on strdup calls later.
    (add_global, write_globals, scan_c_stream):
    Avoid integer overflow when calculating sizes.
    (write_globals, scan_c_stream, scan_lisp_file): Avoid memory leak.
    (scan_c_stream): Check for add_global failure.
make-docfile.c 37.8 KB