mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mitchell Blank Jr <mitch@sfgoth.com>
To: J?rn Engel <joern@wohnheim.fh-wedel.de>
Cc: domen@coderock.org, pavel@suse.cz, linux-kernel@vger.kernel.org
Subject: Re: [patch 2/2] kernel/power/disk.c string fix and if-less iterator
Date: Tue, 21 Jun 2005 05:18:33 -0700	[thread overview]
Message-ID: <20050621121833.GD84485@gaz.sfgoth.com> (raw)
In-Reply-To: <20050621073307.GE27887@wohnheim.fh-wedel.de>

J?rn Engel wrote:
> > -	char *p = "-\\|/";
> > +	char p[] = "-\\|/";
> >  
> >  	printk("Freeing memory...  ");
> >  	while ((tmp = shrink_all_memory(10000))) {
> >  		pages += tmp;
> >  		printk("\b%c", p[i]);
> > -		i++;
> > -		if (i > 3)
> > -			i = 0;
> > +		i = (i + 1) % (sizeof(p) - 1);
> >  	}
> >  	printk("\bdone (%li pages freed)\n", pages);
> >  }
> 
> Isn't "-\\|/" NUL-terminated and hence 5 characters long?  In that
> case, you patch may do funny things.

Yeah, you probably really want to do something like:

	static const char p[] = { '-', '\\', '|', '/' };

	printk("Freeing memory...  ");
	while ((tmp = shrink_all_memory(10000))) {
		pages += tmp;
		printk("\b%c", p[i++ % sizeof(p)]);
	}

By using {} instead of "" to declare the char array you avoid placing the
unneeded '\0' terminator on the string.  Plus it definately should be
declared "static".  I don't see any advantage here of keeping "i" explicitly
in range instead of just doing the "i & 3" on each array lookup; it's one
and per loop either way.

-Mitch

      reply	other threads:[~2005-06-21 12:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 21:57 domen
2005-06-20 22:10 ` Pavel Machek
2005-06-20 23:42   ` Andreas Schwab
2005-06-21  7:36   ` Jörn Engel
2005-06-21  9:07   ` Domen Puncer
2005-06-21 15:15   ` Horst von Brand
2005-06-21  7:33 ` Jörn Engel
2005-06-21 12:18   ` Mitchell Blank Jr [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=20050621121833.GD84485@gaz.sfgoth.com \
    --to=mitch@sfgoth.com \
    --cc=domen@coderock.org \
    --cc=joern@wohnheim.fh-wedel.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    /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

all inboxes | Powered by JetHome®