From 03400241c02dd009c48992ce9b527176d02bb472 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 29 Jul 2000 08:10:46 +0000 Subject: [PATCH] (dir_name): Assert that there are no trailing slashes. --- lib/dirname.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/dirname.c b/lib/dirname.c index acaeba16cd..e6609f1ee8 100644 --- a/lib/dirname.c +++ b/lib/dirname.c @@ -32,6 +32,7 @@ char *malloc (); # define strrchr rindex # endif #endif +#include #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. */ -- 2.30.2