xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Philipp Hahn <hahn@univention.de>
To: xen-devel@lists.xen.org, anjiandi@codeaurora.org
Subject: Re: [PATCH] xen/serial: Fix incorrect length of strncmp for dtuart
Date: Wed, 8 Jun 2016 07:30:37 +0200	[thread overview]
Message-ID: <5757AD7D.7070804@univention.de> (raw)
In-Reply-To: <1465248548-28391-1-git-send-email-anjiandi@codeaurora.org>

[-- Attachment #1: Type: text/plain, Size: 1034 bytes --]

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 <anjiandi@codeaurora.org>
> ---
>  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


[-- Attachment #2: check-strncmp.c --]
[-- Type: text/x-csrc, Size: 325 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

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;
}

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

      parent reply	other threads:[~2016-06-08  5:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 21:29 [PATCH] xen/serial: Fix incorrect length of strncmp for dtuart Jiandi An
2016-06-07  7:29 ` Jan Beulich
2016-06-07  7:58   ` Wei Liu
2016-06-07 10:11 ` Stefano Stabellini
2016-06-08  5:30 ` Philipp Hahn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5757AD7D.7070804@univention.de \
    --to=hahn@univention.de \
    --cc=anjiandi@codeaurora.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).