diff options
author | Patrick Schaaf <brianofish@gmail.com> | 2012-04-02 12:07:46 +0200 |
---|---|---|
committer | Patrick Schaaf <brianofish@gmail.com> | 2012-04-02 12:07:46 +0200 |
commit | 791237e44695d2ee123c8a6f665ef074f5fadfbb (patch) | |
tree | 9c136cbad4da19f06e3e651140ea04f2363bf02f | |
parent | a818bf11e8bbee9b53f0c67de7f7441d998305ab (diff) | |
download | external_bash-791237e44695d2ee123c8a6f665ef074f5fadfbb.zip external_bash-791237e44695d2ee123c8a6f665ef074f5fadfbb.tar.gz external_bash-791237e44695d2ee123c8a6f665ef074f5fadfbb.tar.bz2 |
bash: fix "getcwd: cannot access parent directories: Math result..."
In get_working_directory(), the getcwd call in the __ANDROID__
workaround case was obviously wrong, having sizeof(char *) as a length
argument instead of the length of the malloced string itself. Also, no
check for malloc failure was there.
With this fix, tested on maguro, using bash with the usual prompt
containing pwd references, as well as the pwd bash builtin itself,
no longer spew these annoying messages mentioned in the title.
Also made a small change to sh_invalidnum() to fix compile warnings.
Change-Id: I9546e07731a251f80e410935619ddcf0873694af
-rw-r--r-- | builtins/common.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/builtins/common.c b/builtins/common.c index b69e7a2..03d0d82 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -232,7 +232,7 @@ void sh_invalidnum (s) char *s; { - char *msg; + const char *msg; if (*s == '0' && isdigit (s[1])) msg = _("invalid octal number"); @@ -559,11 +559,13 @@ get_working_directory (for_whom) * out if PWD isn't defined when starting it up on bionic */ char *d = (char *)malloc(sizeof(char) * PATH_MAX); - the_current_working_directory = getcwd (d, sizeof(d)); - if (the_current_working_directory) - the_current_working_directory = d; - else - FREE (d); + if (d) { + the_current_working_directory = getcwd (d, sizeof(char) * PATH_MAX); + if (the_current_working_directory) + the_current_working_directory = d; + else + FREE (d); + } #else # if defined (GETCWD_BROKEN) the_current_working_directory = getcwd (0, PATH_MAX); |