diff options
author | Patrick Schaaf <brianofish@gmail.com> | 2012-04-02 12:07:46 +0200 |
---|---|---|
committer | Dan Pasanen <dan.pasanen@gmail.com> | 2014-10-02 14:26:40 -0500 |
commit | ba43bf0f19072c92a8f82baa9a87df9832d764c5 (patch) | |
tree | fb33c35d5bda89ad0b56c2f3d37d251633fd477e | |
parent | 5e48b325baf2acf97ab7a9c3c81a270ed2c295c5 (diff) | |
download | android_external_bash-ba43bf0f19072c92a8f82baa9a87df9832d764c5.tar.gz android_external_bash-ba43bf0f19072c92a8f82baa9a87df9832d764c5.tar.bz2 android_external_bash-ba43bf0f19072c92a8f82baa9a87df9832d764c5.zip |
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 811ca1b..c728e0b 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); |