Hi Maxim,<br><br>Thanks for your comments.  I thought that &quot;%*s&quot; in the comments above function &quot;ngx_sprintf&quot; is meant to be used for right alignment.  And it turns out to be my own misunderstanding.<br>
<br>Gary<br><br><div class="gmail_quote">On Tue, Aug 10, 2010 at 5:07 PM, Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello!<br>
<div class="im"><br>
On Tue, Aug 10, 2010 at 12:07:30PM +0800, Gary Hu wrote:<br>
<br>
&gt; I found a defect in function &quot;ngx_vslprintf”which doesn&#39;t support right<br>
&gt; alignment format of a string, such as &quot;%40s&quot;, as purported in the comments<br>
&gt; right above the function &quot;ngx_sprintf&quot; in file &quot;src/core/ngx_string.c&quot;.<br>
<br>
</div>It is not clear why you think it should be supported and no<br>
support is a bug.  Both comments and code agree that it&#39;s not<br>
supported.<br>
<br>
Additionally, it&#39;s not clear why do you think it should be<br>
supported for %s, but not for %*s, %V and %v.<br>
<br>
And some patch comments just for completeness:<br>
<div class="im"><br>
&gt; The following is my suggested fix in function &quot;ngx_vslprintf &quot;:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;             ......<br>
&gt;<br>
&gt;            case &#39;s&#39;:<br>
&gt;<br>
&gt;               p = va_arg(args, u_char *);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;                 //<br>
&gt;<br>
&gt;                 // Added  by Gary Hu<br>
&gt;<br>
&gt;                 //<br>
<br>
</div>You may want to use diff -u in the future for submitting patches.<br>
<div class="im"><br>
&gt;                 size_t sublen;<br>
&gt;<br>
&gt;                 size_t padlen;<br>
<br>
</div>Please follow nginx style when submitting patches.  In particular,<br>
please avoid declaring variables in function body.  And note that<br>
nobody stops you from reusing len for padlen, and slen for sublen.<br>
So basically declared variables aren&#39;t needed.<br>
<br>
&gt;<br>
&gt;                 sublen = ngx_strlen(p);<br>
<br>
This will likely cause SIGSEGV/SIGBUS for %*s as p isn&#39;t null<br>
terminated in this case.<br>
<div class="im"><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;                 /* Add padding whitespaces to the output buffer to achieve<br>
&gt; right alignment*/<br>
&gt;<br>
&gt;                 if (width &gt; 0 &amp;&amp; width &gt; sublen)<br>
<br>
</div>Check &quot;width &gt; 0&quot; is useless as both width and sublen are<br>
unsigned.<br>
<div class="im"><br>
&gt;                 {<br>
&gt;<br>
&gt;                     padlen = ngx_min(((size_t) (last - buf)), width - sublen<br>
&gt; );<br>
&gt;<br>
&gt;                     ngx_memset(buf, &#39; &#39;, padlen);<br>
&gt;<br>
&gt;                     buf += padlen;<br>
&gt;<br>
&gt;                 }<br>
&gt;<br>
&gt;                 //<br>
&gt;<br>
&gt;                 // End added by Gary Hu<br>
&gt;<br>
&gt;                 //<br>
<br>
</div>Maxim Dounin<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br>