<font size=2 face="sans-serif">Hi Bart,</font>
<br>
<br><font size=2 face="sans-serif">Thanks for your advice!</font>
<br><font size=2 face="sans-serif">I have updated the solution as follows.
</font>
<br>
<br><font size=1 face="Lucida Console"><b>diff --git a/multipathd/cli_handlers.c
b/multipathd/cli_handlers.c</b></font>
<br><font size=1 face="Lucida Console"><b>index 0b04504..cec40eb 100644</b></font>
<br><font size=1 face="Lucida Console"><b>--- a/multipathd/cli_handlers.c</b></font>
<br><font size=1 face="Lucida Console"><b>+++ b/multipathd/cli_handlers.c</b></font>
<br><font size=1 color=#00c1c2 face="Lucida Console">@@ -1,6 +1,9 @@</font>
<br><font size=1 face="Lucida Console"> /*</font>
<br><font size=1 face="Lucida Console"> * Copyright (c) 2005 Christophe
Varoqui</font>
<br><font size=1 face="Lucida Console"> */</font>
<br><font size=1 color=#00c200 face="Lucida Console">+#define _GNU_SOURCE</font>
<br><font size=1 color=#00c200 face="Lucida Console">+</font>
<br><font size=1 color=#00c200 face="Lucida Console">+#include <stdio.h></font>
<br><font size=1 face="Lucida Console"> #include "checkers.h"</font>
<br><font size=1 face="Lucida Console"> #include "memory.h"</font>
<br><font size=1 face="Lucida Console"> #include "vector.h"</font>
<br><font size=1 color=#00c1c2 face="Lucida Console">@@ -1285,14 +1288,8
@@</font><font size=1 face="Lucida Console"> cli_getprstatus (void * v,
char ** reply, int * len, void * data)</font>
<br>
<br><font size=1 face="Lucida Console"> condlog(3,
"%s: prflag = %u", param, (unsigned int)mpp->prflag);</font>
<br>
<br><font size=1 color=#c20000 face="Lucida Console">-
*reply =(char *)malloc(3);</font>
<br><font size=1 face="Lucida Console"> *len
= 3;</font>
<br><font size=1 color=#c20000 face="Lucida Console">-
memset(*reply,0,3);</font>
<br><font size=1 color=#c20000 face="Lucida Console">-</font>
<br><font size=1 color=#c20000 face="Lucida Console">-</font>
<br><font size=1 color=#c20000 face="Lucida Console">-
sprintf(*reply,"%d\n",mpp->prflag);</font>
<br><font size=1 color=#c20000 face="Lucida Console">-
(*reply)[2]='\0';</font>
<br><font size=1 color=#c20000 face="Lucida Console">-</font>
<br><font size=1 color=#00c200 face="Lucida Console">+</font><font size=1 face="Lucida Console">
</font><font size=1 color=#00c200 face="Lucida Console">asprintf(reply,
"%d\n", mpp->prflag);</font>
<br>
<br><font size=1 face="Lucida Console"> condlog(3,
"%s: reply = %s", param, *reply);</font><font size=2 face="sans-serif">
<br>
</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">发件人:
</font><font size=1 face="sans-serif">Bart Van Assche
<bart.vanassche@sandisk.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">收件人:
</font><font size=1 face="sans-serif"><peng.liang5@zte.com.cn>,
christophe varoqui <christophe.varoqui@free.fr>, </font>
<br><font size=1 color=#5f5f5f face="sans-serif">抄送:
</font><font size=1 face="sans-serif"><zhang.kai16@zte.com.cn>,
<dm-devel@redhat.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">日期:
</font><font size=1 face="sans-serif">2016/08/02
23:20</font>
<br><font size=1 color=#5f5f5f face="sans-serif">主题:
</font><font size=1 face="sans-serif">Re: [dm-devel]
[PATCH] multipathd: fix issue in 'map $map getprstatus' reply</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>On 08/01/2016 06:27 PM, peng.liang5@zte.com.cn wrote:<br>
> From: peng liang <peng.liang5@zte.com.cn><br>
><br>
> add missing newline to 'map|multipath $map getprstatus' reply<br>
><br>
> Signed-off-by: peng liang <peng.liang5@zte.com.cn><br>
> ---<br>
> multipathd/cli_handlers.c | 10 +++++-----<br>
> 1 file changed, 5 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c<br>
> index 8ff4362..0b04504 100644<br>
> --- a/multipathd/cli_handlers.c<br>
> +++ b/multipathd/cli_handlers.c<br>
> @@ -1285,13 +1285,13 @@ cli_getprstatus (void * v, char ** reply,
int * len, void * data)<br>
><br>
>
condlog(3, "%s: prflag = %u", param, (unsigned int)mpp->prflag);<br>
><br>
> -
*reply =(char *)malloc(2);<br>
> -
*len = 2;<br>
> -
memset(*reply,0,2);<br>
> +
*reply =(char *)malloc(3);<br>
> +
*len = 3;<br>
> +
memset(*reply,0,3);<br>
><br>
><br>
> -
sprintf(*reply,"%d",mpp->prflag);<br>
> -
(*reply)[1]='\0';<br>
> +
sprintf(*reply,"%d\n",mpp->prflag);<br>
> +
(*reply)[2]='\0';<br>
<br>
Hello Peng,<br>
<br>
Please use asprintf() instead of malloc() + memset() + sprintf(). See <br>
also </font></tt><a href="https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html"><tt><font size=2>https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html</font></tt></a><tt><font size=2><br>
<br>
Thanks,<br>
<br>
Bart.<br>
<br>
</font></tt>
<br>