Hi,
On Mon, 2011-07-04 at 15:52 +0800, Xiangfu Liu wrote:
> diff --git a/direct/rtems/rtems.c b/direct/rtems/rtems.c
> index cec053b..d81c0d3 100644
> --- a/direct/rtems/rtems.c
> +++ b/direct/rtems/rtems.c
> @@ -391,25 +391,37 @@ static int ycb_eval_path(const char *pathname, size_t
> pathnamelen, int flags, rt
> static int ycb_eval_path_for_make(const char *path,
> rtems_filesystem_location_info_t *pathloc, const char **name)
> {
> char *s;
> - char *path2;
> - int r;
> + char *path1, *path2;
> + int r, i;
> +
> + path1 = strdup(path);
> + if(path1 == NULL) {
> + errno = ENOMEM;
> + return -1;
> + }
> + i = strlen(path1) - 1;
> + while(path1[i] == '/') {
> + path1[i] = '\0';
> + i--;
> + }
This can break badly when passed an empty string or a string containing
only slashes. Rewrite the loop condition as:
(i >= 0) && (path1[i] == '/')
> @@ -462,9 +474,20 @@ static rtems_filesystem_node_types_t
> ycb_node_type(rtems_filesystem_location_inf
>
> static int ycb_mknod(const char *path, mode_t mode, dev_t dev,
> rtems_filesystem_location_info_t *pathloc)
> {
> + char *name, *s;
> + int ret = 0;
> +
> struct yaffs_obj *parent = pathloc->node_access;
> struct yaffs_softc *sc = parent->my_dev->driver_context;
>
> + name = strdup(path);
> + if(name == NULL) {
> + errno = ENOMEM;
> + return -1;
> + }
> + s = strchr(name, '/');
> + *s = '\0';
strchr can return NULL (and in most cases will).
S.
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode
Twitter: www.twitter.com/milkymistvj
Ideas? http://milkymist.uservoice.com