[vlc-commits] ftp: publicize IsASCII() helper
Rémi Denis-Courmont
git at videolan.org
Sat Jul 7 10:37:39 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jul 7 11:27:29 2018 +0300| [39077be1b9192f20a3a0e7aa4ea34cb06076c686] | committer: Rémi Denis-Courmont
ftp: publicize IsASCII() helper
Also document and avoid sign overflow (on platforms where char is
unsigned).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=39077be1b9192f20a3a0e7aa4ea34cb06076c686
---
include/vlc_charset.h | 21 +++++++++++++++++++++
modules/access/ftp.c | 9 ---------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/include/vlc_charset.h b/include/vlc_charset.h
index 05092257a4..3c03b97a16 100644
--- a/include/vlc_charset.h
+++ b/include/vlc_charset.h
@@ -74,6 +74,27 @@ VLC_USED static inline const char *IsUTF8(const char *str)
}
/**
+ * Checks ASCII validity.
+ *
+ * Checks whether a null-terminated string is a valid ASCII bytes sequence
+ * (non-printable ASCII characters 1-31 are permitted).
+ *
+ * \param str string to check
+ *
+ * \retval str the string is a valid null-terminated ASCII sequence
+ * \retval NULL the string is not an ASCII sequence
+ */
+VLC_USED static inline const char *IsASCII(const char *str)
+{
+ unsigned char c;
+
+ for (const char *p = str; (c = *p) != '\0'; p++)
+ if (c >= 0x80)
+ return NULL;
+ return str;
+}
+
+/**
* Removes non-UTF-8 sequences.
*
* Replaces invalid or <i>over-long</i> UTF-8 bytes sequences within a
diff --git a/modules/access/ftp.c b/modules/access/ftp.c
index 0edd5c1537..d6a5404367 100644
--- a/modules/access/ftp.c
+++ b/modules/access/ftp.c
@@ -576,15 +576,6 @@ static void FeaturesCheck( void *opaque, const char *feature )
features->b_mlst = true;
}
-static const char *IsASCII( const char *str )
-{
- int8_t c;
- for( const char *p = str; (c = *p) != '\0'; p++ )
- if( c < 0 )
- return NULL;
- return str;
-}
-
static int Connect( vlc_object_t *p_access, access_sys_t *p_sys, const char *path )
{
if( Login( p_access, p_sys, path ) < 0 )
More information about the vlc-commits
mailing list