From 43cc92d6e41804cf1034e1d6e3cdf35e299bd196 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 11 Aug 2023 14:55:21 +0800 Subject: [PATCH] Minor adjustments to Android port * java/org/gnu/emacs/EmacsService.java (readDirectoryEntry): Also refrain from returning NULL or file names containing non-representable NULL bytes. * src/callproc.c (get_current_directory): Clean up by employing android_is_special_directory. --- java/org/gnu/emacs/EmacsService.java | 8 ++++++-- src/callproc.c | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 379b1d30eda..cee823abc83 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java @@ -1503,9 +1503,13 @@ public final class EmacsService extends Service return entry; } - /* Skip this entry if its name cannot be represented. */ + /* Skip this entry if its name cannot be represented. NAME + can still be null here, since some Cursors are permitted to + return NULL if INDEX is not a string. */ - if (name.equals ("..") || name.equals (".") || name.contains ("/")) + if (name == null || name.equals ("..") + || name.equals (".") || name.contains ("/") + || name.contains ("\0")) continue; /* Now, look for its type. */ diff --git a/src/callproc.c b/src/callproc.c index 0645c2c3e18..dc37dfdc01f 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -170,10 +170,11 @@ get_current_directory (bool encode) /* If DIR is an asset directory or a content directory, return the home directory instead. */ - if (encode && (!strcmp (SSDATA (dir), "/assets") - || !strncmp (SSDATA (dir), "/assets/", 8) - || !strcmp (SSDATA (dir), "/content") - || !strncmp (SSDATA (dir), "/content/", 9))) + if (encode + && (android_is_special_directory (SSDATA (dir), + "/assets") + || android_is_special_directory (SSDATA (dir), + "/content"))) dir = build_string ("~"); #endif /* HAVE_ANDROID && ANDROID_STUBIFY */ -- 2.39.2