diff options
author | Jim Meyering <jim@meyering.net> | 2000-07-29 08:10:46 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-07-29 08:10:46 +0000 |
commit | 3819c2d7cb6b57a05d01381b67e1163e5467ee67 (patch) | |
tree | 28983c646f7385950fb6331ad52faaacdf767ad8 /lib/dirname.c | |
parent | ba8620bf0156d5f8594a5620b3194e5606a6165e (diff) | |
download | coreutils-3819c2d7cb6b57a05d01381b67e1163e5467ee67.tar.xz |
(dir_name): Assert that there are no trailing slashes.
Diffstat (limited to 'lib/dirname.c')
-rw-r--r-- | lib/dirname.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/dirname.c b/lib/dirname.c index acaeba16c..e6609f1ee 100644 --- a/lib/dirname.c +++ b/lib/dirname.c @@ -32,6 +32,7 @@ char *malloc (); # define strrchr rindex # endif #endif +#include <assert.h> #ifndef ISSLASH # define ISSLASH(C) ((C) == '/') @@ -52,6 +53,13 @@ dir_name (const char *path) int length; /* Length of result, not including NUL. */ slash = strrchr (path, '/'); + + /* Make sure there are no trailing slashes. */ + assert (slash == NULL /* There are no slashes in PATH. */ + || slash[1] != 0 /* There is a non-NUL byte after the last slash. */ + || path == slash /* PATH is just `/'. */ + ); + if (slash == 0) { /* File is in the current directory. */ |