From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Hahn Subject: Re: [PATCH] xen/serial: Fix incorrect length of strncmp for dtuart Date: Wed, 8 Jun 2016 07:30:37 +0200 Message-ID: <5757AD7D.7070804@univention.de> References: <1465248548-28391-1-git-send-email-anjiandi@codeaurora.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080001010601060101030602" Return-path: In-Reply-To: <1465248548-28391-1-git-send-email-anjiandi@codeaurora.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel@lists.xen.org, anjiandi@codeaurora.org List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------080001010601060101030602 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello, Am 06.06.2016 um 23:29 schrieb Jiandi An: > In serial_parse_handler(), length of strncmp for dtuart should have been > 6, not 5. > > Signed-off-by: Jiandi An > --- > xen/drivers/char/serial.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c > index c583a48..0fc5ced 100644 > --- a/xen/drivers/char/serial.c > +++ b/xen/drivers/char/serial.c > @@ -310,7 +310,7 @@ int __init serial_parse_handle(char *conf) > goto common; > } > > - if ( !strncmp(conf, "dtuart", 5) ) > + if ( !strncmp(conf, "dtuart", 6) ) Do you really want to check for a prefix, that it that conf starts with "dtuart"? If you want to check for an exact string match, you need to include the trailing \0! In that case just use "strcmp()" as there is (AFAIK) not reason to use the n-variant as one of your string is a constant already and thus the comparison will terminate when the \0 of that const-string is reached. Philipp --------------080001010601060101030602 Content-Type: text/x-csrc; name="check-strncmp.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="check-strncmp.c" #include #include #include static const char *confs[] = { "dtuar", "dtuart", "dtuartx", NULL }; int main(void) { int i; for (i = 0; confs[i]; i++) { const char *conf = confs[i]; printf("%s\t%d\t%d\n", conf, strncmp(conf, "dtuart", 5), strncmp(conf, "dtuart", 6)); } return 0; } --------------080001010601060101030602 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --------------080001010601060101030602--