From ba5614fb0e516f46bcea5fc578922673f37fc820 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 26 Feb 2026 21:44:09 +0100 Subject: [PATCH] cleanup: use auto_FILE and handle fopen failure in command_docgen --- src/command/cmd_defs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index d3091279..ce39f3c5 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2976,8 +2976,14 @@ command_docgen(void) cmds = g_list_insert_sorted(cmds, (gpointer)pcmd, (GCompareFunc)_cmp_command); } - FILE* toc_fragment = fopen("toc_fragment.html", "w"); - FILE* main_fragment = fopen("main_fragment.html", "w"); + auto_FILE FILE* toc_fragment = fopen("toc_fragment.html", "w"); + auto_FILE FILE* main_fragment = fopen("main_fragment.html", "w"); + + if (!toc_fragment || !main_fragment) { + printf("\nError opening html files: %s.\n", strerror(errno)); + g_list_free(cmds); + return; + } fputs("\n", toc_fragment); - fclose(toc_fragment); - fclose(main_fragment); printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); g_list_free(cmds); }