From: Andreas Schweigstill <andreas@schweigstill.de>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [RFC/PATCH] Add expr command
Date: Wed, 13 Feb 2008 15:20:56 +0100 [thread overview]
Message-ID: <47B2FCC8.3030003@schweigstill.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0802130747530.14735@blarg.am.freescale.net>
Hello!
Kumar Gala schrieb:
> Add a simple expr command that will set an env variable as the result
> of the command.
Good idea! I have been missing this for a long time but I also was too
lazy to implement it.
> + /* Validate arguments */
> + if ((argc != 5)) {
> + printf("Usage:\n%s\n", cmdtp->usage);
> + return 1;
> + }
It should also be checked if the operator has a length of exactly
one character in order to prevent typos.
+ /* Validate arguments */
+ if ((argc != 5) || (strlen(argv[3]) != 1)) {
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
May we rely on the compiler optimizing the above expression so
strlen() != 1 will only be evaluated if argc == 5 ? Probably we
have to write
+ ulong a, b;
+ char buf[16];
+ int valid = 0;
+
+ /* Validate arguments */
+ if (argc == 5) {
+ if (strlen(argv[3]) == 1) {
+ valid = 1;
+ }
+ }
+ if (!valid) {
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
Regards
Andreas Schweigstill
--
Dipl.-Phys. Andreas Schweigstill
Schweigstill IT | Embedded Systems
Schauenburgerstra?e 116, D-24118 Kiel, Germany
Phone: (+49) 431 5606-435, Fax: (+49) 431 5606-436
Mobile: (+49) 171 6921973, Web: http://www.schweigstill.de/
next prev parent reply other threads:[~2008-02-13 14:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-13 13:49 [U-Boot-Users] [RFC/PATCH] Add expr command Kumar Gala
2008-02-13 14:20 ` Andreas Schweigstill [this message]
2008-02-13 16:06 ` Scott Wood
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=47B2FCC8.3030003@schweigstill.de \
--to=andreas@schweigstill.de \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.