Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_C646F14F79601B2671CCC1CDC21CCF4B7008@qq.com>
Date: Sat, 6 May 2023 13:24:15 +0800
From: "847567161" <847567161@...com>
To: "musl" <musl@...ts.openwall.com>
Subject: Re: Question: Why vfprintf call twice printf_core?

Thanks for your reply.


1、 Could you tell us what the format string is in your case?
--------------
        snprintf(buf, sizeof(buf), "this is a more typical error message with detail: %s", "No such file or directory");         



2、First call to printf_core() checks to see if there are any major&nbsp;problems with the format string
--------------
Maybe the second call can also checks the format error?


3、if the string is using positional arguments (e.g. "%2$d"), also establishes the types of these arguments and writes them into an array.
--------------
I use above format string,I think it's a&nbsp;typical error message, I found the first printf_core do string traversal and cost some time showed in perf.


If we remove the first function call when we don't use ("%2$d"), is there any problem?Or do you have some advice for impove the vfprintf performance in common scenarios?


Regards&nbsp;


Chuang Yin


------------------&nbsp;Original&nbsp;------------------
From:                                                                                                                        "musl"                                                                                    <nullplan@....net&gt;;
Date:&nbsp;Sat, May 6, 2023 11:53 AM
To:&nbsp;"musl"<musl@...ts.openwall.com&gt;;

Subject:&nbsp;Re: [musl] Question: Why vfprintf call twice printf_core?



Am Sat, May 06, 2023 at 11:29:36AM +0800 schrieb 847567161:
&gt; Hello,
&gt;&nbsp;&nbsp;&nbsp;&nbsp; I'm analyzing vfprintf performance, I don't know why musl call
&gt;&nbsp;&nbsp;&nbsp;&nbsp; "printf_core(0, fmt, &amp;amp;ap2, nl_arg, nl_type)" here. Could you
&gt;&nbsp;&nbsp;&nbsp;&nbsp; tell me the reason?
&gt;&nbsp;&nbsp;&nbsp;&nbsp; https://gitee.com/openharmony/third_party_musl/blob/master/src/stdio/vfprintf.c#L668
&gt;&nbsp;&nbsp;&nbsp;&nbsp; More info:&nbsp;&nbsp;&nbsp; I use gdb to debug vfprintf , I found it return
&gt;&nbsp;&nbsp;&nbsp;&nbsp; directly when calling printf_core firstly which file parameter is
&gt;&nbsp;&nbsp;&nbsp;&nbsp; 0.
&gt;&nbsp;&nbsp;&nbsp;&nbsp; https://gitee.com/openharmony/third_party_musl/blob/master/src/stdio/vfprintf.c#L526
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Best Regards Chuang Yin

First call to printf_core() checks to see if there are any major
problems with the format string, and if the string is using positional
arguments (e.g. "%2$d"), also establishes the types of these arguments
and writes them into an array. Second call does the actual work.

The shortcut after the first printf_core() call is an error exit. That
means the format string is invalid. Could you tell us what the format
string is in your case?

Additionally, there is something weird with your mail client; it is
writing HTML entities into the plain text.

Ciao,
Markus
Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.