On Mon, 14 Sep 2026 22:16:12 +0200
Markus Elfring <[email protected]> wrote:

> …
> > +++ b/scripts/kallsyms.c  
> …
> > @@ -413,26 +438,24 @@ static void write_src(void)
> >             /* Encode length with ULEB128. */
> >             if (table[i]->len <= 0x7F) {
> >                     /* Most symbols use a single byte for the length. */
> > -                   printf("\t.byte 0x%02x", table[i]->len);
> > +                   fputc(table[i]->len, out_bin_file);
> >                     off += table[i]->len + 1;
> >             } else {
> >                     /* "Big" symbols use two bytes. */
> > -                   printf("\t.byte 0x%02x, 0x%02x",
> > -                           (table[i]->len & 0x7F) | 0x80,
> > -                           (table[i]->len >> 7) & 0x7F);
> > +                   fputc((table[i]->len & 0x7F) | 0x80, out_bin_file);
> > +                   fputc((table[i]->len >> 7) & 0x7F, out_bin_file);
> >                     off += table[i]->len + 2;
> >             }
> > -           for (k = 0; k < table[i]->len; k++)
> > -                   printf(", 0x%02x", table[i]->sym[k]);
> > +           fwrite(table[i]->sym, 1, table[i]->len, out_bin_file);
> >  
> >             /*
> >              * Now that we wrote out the compressed symbol name, restore the
> > -            * original name and print it in the comment.
> > +            * original name for the comments below.
> >              */
> >             expand_symbol(table[i]->sym, table[i]->len, buf);
> >             strcpy((char *)table[i]->sym, buf);
> > -           printf("\t/* %s */\n", table[i]->sym);
> >     }
> > +   write_incbin(out_bin_name, bin_start, bin_pos(out_bin_file));
> >     printf(".size kallsyms_names, . - kallsyms_names\n");
> >     printf("\n");
> >    
> …
> 
> I suggest to avoid return value ignorance a bit more.
> https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/error-handling-err/err33-c/
> https://cwe.mitre.org/data/definitions/252.html

And I suggest you do some real coding...
The error is sticky and can be checked using ferror().
Code that looks at the return value from fprintf() fwrite() etc is very
often broken because the only time they can actual fail is when the
buffer is flushed during close.
Adding error checks to every call just make the code unreadable.

David

> 
> Regards,
> Markus


Reply via email to