From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Wed, 19 Oct 2011 18:46:09 -0400 Subject: [U-Boot] [PATCH 1/4] cmdline: Add linux command line munging tools In-Reply-To: <1319063459-4804-2-git-send-email-dianders@chromium.org> References: <1319063459-4804-1-git-send-email-dianders@chromium.org> <1319063459-4804-2-git-send-email-dianders@chromium.org> Message-ID: <201110191846.10287.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wednesday 19 October 2011 18:30:56 Doug Anderson wrote: > --- /dev/null > +++ b/common/cmdline.c > > +/* > + * To run unit tests in this file: > + * gcc -DRUN_UNITTESTS -Wall -Werror common/cmdline.c -o cmdline && > ./cmdline > + */ > +#ifdef RUN_UNITTESTS i'm not sure this part should be merged ... better to keep on the back burner while Simon sorts out testing framework with new sandbox arch. > +void add_cmdline_param(char *cmdline, const char *toappend, int bufsize) bufsize should be size_t > +{ > + int cmdline_len = strlen(cmdline); cmdline_len should be size_t > + if (cmdline_len == 0) > + strncat(cmdline, toappend, bufsize-1); > + else { > + int bytes_avail = bufsize - cmdline_len; > + > + if (bytes_avail <= 0) { > + assert(bytes_avail == 0); > + return; > + } > + cmdline[bufsize-1] = '\0'; > + cmdline[cmdline_len] = ' '; > + strncpy(&cmdline[cmdline_len+1], toappend, > + bytes_avail-2); > + } hmm, i feel like this should be simpler and not need that branch if (cmdline_len) cmdline[cmdline_len++] = ' '; if (bufsize <= cmdline_len) return; memcpy(&cmdline[cmdline_len], toappend, bufsize - cmdline_len - 1); cmdline[bufsize] = '\0'; -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20111019/bf949527/attachment.pgp