On Sun, Jun 10, 2012 at 3:45 PM, Glenn Fowler <[email protected]> wrote:
[snip]
>
> I believe this one will work
>
> - if(memcmp(name,pp->name,len)==0 && (pp->name[len]==':' ||
> pp->name[len]==0))
> + if(len <= strlen(pp->name) && memcmp(name,pp->name,len)==0 &&
> (pp->name[len]==':' || pp->name[len]==0))
>
> pp->name is a ':' separated list of dirs, except for dirN '\0' terminated
>
> dir1:dir2:...:dirN
>
> we are checking if name length len is the first component in the list
> if (len > strlen(the list)) then it can't be the first component
> otherwise memcmp(name,pp->name,len) and pp->name[len] are safe to access
Nitpicking: You still have an extra |strlen()| and you execute the
|memcmp()| too often compared to the attached version (attached as
"astksh20120606_gis_path_addcomp_crash003.diff.txt" (note I took the
liberty of changing an |int| to |ssize_t| as tiny cleanup to allow
larger strings in the future)) ... :-)
AFAIK either version will do but I guess my might be a tiny it faster... :-)
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
diff -r -u src/cmd/ksh93/sh/path.c
build_i386_64bit_opt_extrabuiltins/src/cmd/ksh93/sh/path.c
--- src/cmd/ksh93/sh/path.c Tue Jun 5 19:18:06 2012
+++ src/cmd/ksh93/sh/path.c Sun Jun 10 20:11:43 2012
@@ -1447,6 +1447,9 @@
#endif /* SHOPT_ACCT */
+#ifndef MIN
+#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
+#endif
/*
* add a pathcomponent to the path search list and eliminate duplicates
@@ -1455,7 +1458,8 @@
static Pathcomp_t *path_addcomp(Shell_t *shp,Pathcomp_t *first, Pathcomp_t
*old,const char *name, int flag)
{
register Pathcomp_t *pp, *oldpp;
- int len, offset=staktell();
+ size_t mlen;
+ ssize_t len, offset=staktell();
if(!(flag&PATH_BFPATH))
{
register const char *cp = name;
@@ -1470,7 +1474,10 @@
len = strlen(name);
for(pp=first; pp; pp=pp->next)
{
- if(memcmp(name,pp->name,len)==0 && (pp->name[len]==':' ||
pp->name[len]==0))
+ mlen = MIN(len, pp->len);
+ if((name[mlen]== 0) &&
+ (pp->name[mlen]==':' || pp->name[mlen]==0) &&
+ (memcmp(name,pp->name, mlen)==0))
{
pp->flags |= flag;
return(first);
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers