-
Notifications
You must be signed in to change notification settings - Fork 34
Add -z|--zero options to basename and dirname builtins and fix support for PATH_LEADING_SLASHES (plus small buffer overflow fix) #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
90b459c
4aaac77
e6371a2
258891c
4795d73
dcff672
8dd17b6
251cf10
3b9ff9e
c8feb1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,24 +194,30 @@ static Namval_t *scope(Namval_t *np,struct lval *lvalue,int assign) | |
return np; | ||
} | ||
|
||
static Math_f sh_mathstdfun(const char *fname, size_t fsize, short * nargs) | ||
/* lookup a function in the standard math function table */ | ||
static Math_f sh_mathstdfun(const char *fname, size_t fsize, short *nargs) | ||
{ | ||
const struct mathtab *tp; | ||
char c = fname[0]; | ||
for(tp=shtab_math; *tp->fname; tp++) | ||
char firstc = fname[0]; | ||
/* first byte of tp->fname is num. args and return type, unless empty */ | ||
for(tp=shtab_math; tp->fname[0]=='\0'; tp++) | ||
{ | ||
if(*tp->fname > c) | ||
/* shtab_math is in alphabetic order - if first character is greater, we're done */ | ||
if(tp->fname[1] > firstc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is incorrect, because it assumes that shtab_math is in alphabetical order. Unfortunately, a look at the generated shtab_math in arch/*/src/cmd/ksh93/FEATURE/math shows that it is not sorted, alphabetically or otherwise. What on earth AT&T meant to accomplish with the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment provided for historical interest; feel free to ignore. I was curious why the In the earliest available version (1995), shtab_math was in fact hardcoded and sorted alphabetically, and the By the next available version from 1999, |
||
break; | ||
if(tp->fname[1]==c && tp->fname[fsize+1]==0 && strncmp(&tp->fname[1],fname,fsize)==0) | ||
if(tp->fname[1]==firstc && strncmp(&tp->fname[1],fname,fsize)==0 && tp->fname[fsize+1]=='\0') | ||
{ | ||
if(nargs) | ||
*nargs = *tp->fname; | ||
{ | ||
*nargs = tp->fname[0]; | ||
} | ||
return tp->fnptr; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
|
||
int sh_mathstd(const char *name) | ||
{ | ||
return sh_mathstdfun(name,strlen(name),NULL)!=0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is incorrect; it inverts the sense of the second
for
expression, so that no math function is ever found. Thatfor
statement should not change.