
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