criticic / llpp

llpp original source code before it turned to protestware. NOTE: changes are made on the "latest" branch, master is locked and remains as it was.
Other
28 stars 6 forks source link

Build fails #2

Closed algo99 closed 1 year ago

algo99 commented 1 year ago

The build fails at link.c on Fedora 37:

link.o
./link.c: In function ‘ml_getfileannot’:
./link.c:2562:5: error: ‘file_params’ may be used uninitialized [-Werror=maybe-uninitialized]
 2562 |     pdf_get_embedded_file_params (state.ctx, fs, file_params);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./link.c:2561:31: note: ‘file_params’ was declared here
 2561 |     pdf_embedded_file_params *file_params;
      |                               ^~~~~~~~~~~
cc1: all warnings being treated as errors
ocamlc -ccopt "-g -std=c11 -I build/mupdf/include -I build/mupdf/thirdparty/freetype/include -Wall -Werror -Wextra -pedantic -O2 -D_POSIX_C_SOURCE -DGL_H='<GL/gl.h>' -DTEXT_TYPE=GL_TEXTURE_RECTANGLE_ARB -MMD -MF build/link.o.dep -MT_" -o build/link.o -c ./link.c failed
build failed

and I think the compiler is right now :) because this code looks suspicious for me

link.c: 2549

ML (getfileannot (value ptr_v, value n_v))
{
    ...
    pdf_embedded_file_params *file_params;
    pdf_get_embedded_file_params (state.ctx, fs, file_params);
    ret_v = caml_copy_string (file_params->filename);
    ...
 }

because function pdf_get_embedded_file_params does not allocate memory for file_params structure.

This patch solves the problem: ```diff diff --git a/link.c b/link.c index 7bbf73a..ecf6189 100644 --- a/link.c +++ b/link.c @@ -2558,9 +2558,9 @@ ML (getfileannot (value ptr_v, value n_v)) pdf_obj *fs = pdf_dict_get (state.ctx, pdf_annot_obj (state.ctx, slink->u.annot), PDF_NAME (FS)); - pdf_embedded_file_params *file_params; - pdf_get_embedded_file_params (state.ctx, fs, file_params); - ret_v = caml_copy_string (file_params->filename); + pdf_embedded_file_params file_params; + pdf_get_embedded_file_params (state.ctx, fs, &file_params); + ret_v = caml_copy_string (file_params.filename); unlock (__func__); CAMLreturn (ret_v); ```

Not sure though why you don't see this error. I used system ocaml-14.4.0 and Fedora-37 has gcc-12.2.1

criticic commented 1 year ago

extremely confusing why i dont get any of the errors others get. i have implemented your patch though