cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] dlm_controld: fix name printing error in logging
Date: Fri, 25 Apr 2014 12:25:04 +0100	[thread overview]
Message-ID: <535A4610.6090909@redhat.com> (raw)
In-Reply-To: <1398410508-6198-1-git-send-email-lzhong@suse.com>

Hi,

On 25/04/14 08:21, Lidong Zhong wrote:
> When the length of name_in is NAME_ID_SIZE, the last byte of the name
> and a whitespace will get lost.
>
> Signed-off-by: Lidong Zhong <lzhong@suse.com>
> ---
>   dlm_controld/logging.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c
> index 9347e43..ea879e8 100644
> --- a/dlm_controld/logging.c
> +++ b/dlm_controld/logging.c
> @@ -122,7 +122,7 @@ static void log_save_str(int len, char *log_buf, unsigned int *point,
>   void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
>   {
>   	va_list ap;
> -	char name[NAME_ID_SIZE + 1];
> +	char name[NAME_ID_SIZE + 2];
>   	uint32_t level = level_in & 0x0000FFFF;
>   	uint32_t extra = level_in & 0xFFFF0000;
>   	int ret, pos = 0;
> @@ -132,7 +132,7 @@ void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
>   	memset(name, 0, sizeof(name));
>   
>   	if (name_in)
> -		snprintf(name, NAME_ID_SIZE, "%s ", name_in);
> +		snprintf(name, NAME_ID_SIZE + 2, "%s ", name_in);
>   
>   	ret = snprintf(log_str + pos, len - pos, "%llu %s",
>   		       (unsigned long long)monotime(), name);
It seems a bit odd to use a temporary buffer here... why not just print 
the name directly in the second snprintf() call? Something like this:

if (name_in)

	ret = snprintf(log_str + pos, len - pos, "%llu %s ",
  		       (unsigned long long)monotime(), name_in);

     else

         ret = snprintf(log_str + pos, len - pos, "%llu ",
  		       (unsigned long long)monotime());

Or even:

	ret = snprintf(log_str + pos, len - pos, name_in ? "%llu %s " : "%llu ",
		       (unsigned long long)monotime(), name_in);


Steve.



  reply	other threads:[~2014-04-25 11:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25  7:21 [Cluster-devel] [PATCH] dlm_controld: fix name printing error in logging Lidong Zhong
2014-04-25 11:25 ` Steven Whitehouse [this message]
2014-04-25 15:59 ` David Teigland

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=535A4610.6090909@redhat.com \
    --to=swhiteho@redhat.com \
    /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).