I'm currently in chroot building LFS. I was trying to compile a legacy project called install-log
but I get this error:
(lfs chroot) root:/src/install-log# make install
cc -MMD -c -o list.o list.c
In file included from list.c:22:
list.c: In function 'fprintf_node':
list.c:145:23: error: invalid initializer
145 | va_list ap2 = va_arg(ap, va_list);
| ^~~~~~
make: *** [Makefile:55: list.o] Error 1
The source of the program is present on the WayBack Machine and this is the program's home page on SourceForge.
I have no idea what is wrong as I'm not very technical. If someone could help, it would be appreciated!
This is the code snippet:
/* Prints 'node', using 'ap' as a formatting guide. */
static void fprintf_node(list_t* node, va_list ap)
{
FILE* file = va_arg(ap, FILE*);
char* fmt = va_arg(ap, char*);
/*line 145-->*/ va_list ap2 = va_arg(ap, va_list);
/* An individual %! token */
int token_cap = 8;
int token_len = 0;
char* token = xmalloc(token_cap);
/* The expanded version of one %! token */
int exp_token_cap = 8;
int exp_token_len = 0;
char* exp_token = xmalloc(exp_token_cap);
/* The format string with all %!'s expanded */
char* fmt2 = strdup(fmt);
int fmt2_len = strlen(fmt2);
int fmt2_cap = strlen(fmt2);
char* fmt2_p = fmt2;
The code in the package tries to use a generic function,
proc_list_va()
(defined inlist.c
), to apply two different functions to each element of the list (once inlist.c
, once indatabase.c
). In doing so, it contorts the code horribly. I assume it worked with the available compilers on the test platforms when the code was released in May 2003, but it doesn't compile happily now.It seems to me that the best fix is to use separate apply functions for the two different cases; it simplifies the code dramatically. I renamed the driving functions to
apply_print_node()
inlist.c
and toapply_prev_file()
indatabase.c
. I removed the declaration ofproc_list_va()
frominstall-log.h
.With the changes, the code compiles 'cleanly' under the default options for GCC 11.2.0 on a MacBook Pro running macOS Big Sur 11.6.5. That is, the makefile uses only
-MMD
to generate dependency information:There are no complaints from the compiler with these options. It would be worth adding
-O
or-O3
to the compiler command lines. I've not dared to try my normal set of compiler options (-O3 -g -std=c11 -Wall -Wextra -Werror -Wmissing-prototypes -Wstrict-prototypes -fno-common
).I'm not sure what's the best way to get the information to you. There's a 'patch' format file (series of
diff -u
outputs) for the three changed files below. If you would like a tar-ball of the original and modified source files, contact me (see my SO profile, and include "SO 7182-0194" in the subject line). The original versions of the files were stashed in theSafe
subdirectory and the names have a timestamp attached recording when I downloaded them. It kept the originals unsullied while I hacked on the code. The primary changes are inlist.c
,database.c
andinstall-log.h
but I also made sundry other modernization changes in other files.Hmmm, it occurs to me that since the 'apply' functions are now each calling a single function, there's no need for the function pointer argument. They could simply call the appropriate function directly. That's a refinement you can make if you want.
I should state that I've only compiled the code; I've not attempted to run it.
I did not manage to download the README file from the WayBack Machine (Internet Archive) at http://web.archive.org/web/20051214084919/http://ioioio.net:80/devel/install-log/install-log/. The CVS directory was likewise not available for download.