[vlc-commits] [Git][videolan/vlc][master] 5 commits: text: let vlc_towc() return an ssize_t
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Feb 17 08:33:47 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
b036c26e by Steve Lhomme at 2023-02-17T08:20:49+00:00
text: let vlc_towc() return an ssize_t
size_t is not well suited to return -1 to 4 values. We can also get rid of all
the (size_t)-1 casts.
- - - - -
d8956d40 by Steve Lhomme at 2023-02-17T08:20:49+00:00
text/unicode: fix usage of potential negative return code
Just as the code above, we return NULL when a bogus char is found in the string.
- - - - -
ca9780f5 by Steve Lhomme at 2023-02-17T08:20:49+00:00
avcodec: don't use avformat if HAVE_LIBAVFORMAT_AVFORMAT_H is not defined
- - - - -
a2e2ff67 by Steve Lhomme at 2023-02-17T08:20:49+00:00
libmp4: explicitly use negative value for unsigned return value
This is the same format used to check the returned value.
(cherry picked from commit 1bdc69ccf75dd117ccba3e7cbad514666e336242)
- - - - -
d14929e8 by Steve Lhomme at 2023-02-17T08:20:49+00:00
es_out: don't call sout_StreamSetPCR() if not compiled with sout
- - - - -
9 changed files:
- include/vlc_charset.h
- modules/codec/avcodec/avcodec.c
- modules/demux/mp4/libmp4.c
- modules/logger/json.c
- src/config/help.c
- src/input/es_out.c
- src/test/utf8.c
- src/text/strings.c
- src/text/unicode.c
Changes:
=====================================
include/vlc_charset.h
=====================================
@@ -42,12 +42,12 @@
*
* \return the number of bytes occupied by the decoded code point
*
- * \retval (size_t)-1 not a valid UTF-8 sequence
+ * \retval -1 not a valid UTF-8 sequence
* \retval 0 null character (i.e. str points to an empty string)
* \retval 1 (non-null) ASCII character
* \retval 2-4 non-ASCII character
*/
-VLC_API size_t vlc_towc(const char *str, uint32_t *restrict pwc);
+VLC_API ssize_t vlc_towc(const char *str, uint32_t *restrict pwc);
/**
* Checks UTF-8 validity.
@@ -61,11 +61,11 @@ VLC_API size_t vlc_towc(const char *str, uint32_t *restrict pwc);
*/
VLC_USED static inline const char *IsUTF8(const char *str)
{
- size_t n;
+ ssize_t n;
uint32_t cp;
while ((n = vlc_towc(str, &cp)) != 0)
- if (likely(n != (size_t)-1))
+ if (likely(n != -1))
str += n;
else
return NULL;
@@ -114,11 +114,11 @@ VLC_USED static inline const char *IsASCII(const char *str)
static inline char *EnsureUTF8(char *str)
{
char *ret = str;
- size_t n;
+ ssize_t n;
uint32_t cp;
while ((n = vlc_towc(str, &cp)) != 0)
- if (likely(n != (size_t)-1))
+ if (likely(n != -1))
str += n;
else
{
=====================================
modules/codec/avcodec/avcodec.c
=====================================
@@ -63,7 +63,9 @@ static const char *const enc_hq_list_text[] = {
#endif
#ifdef MERGE_FFMPEG
-# include "../../demux/avformat/avformat.h"
+# ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
+# include "../../demux/avformat/avformat.h"
+# endif
# include "../../access/avio.h"
# include "../../packetizer/avparser.h"
#endif
@@ -200,7 +202,9 @@ vlc_module_begin ()
#ifdef MERGE_FFMPEG
add_submodule ()
+# ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
# include "../../demux/avformat/avformat.c"
+# endif
add_submodule ()
AVIO_MODULE
add_submodule ()
=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -1680,9 +1680,9 @@ static uint64_t MP4_ReadLengthDescriptor( uint8_t **restrict bufp,
do
{
if (unlikely(len == 0))
- return -1; /* end of bit stream */
+ return UINT64_C(-1); /* end of bit stream */
if (unlikely(value > (UINT64_MAX >> 7)))
- return -1; /* integer overflow */
+ return UINT64_C(-1); /* integer overflow */
b = *(buf++);
len--;
=====================================
modules/logger/json.c
=====================================
@@ -4,7 +4,7 @@
* Copyright © 2021 Videolabs
*
* Authors : Nicolas Le Quec
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -120,7 +120,8 @@ static void JsonPrintString(FILE *stream, const char *str)
else
{
uint32_t bytes;
- size_t len = vlc_towc(str, &bytes);
+ ssize_t len = vlc_towc(str, &bytes);
+ assert(len > 0);
PrintUTF8Char(stream, bytes);
str += len - 1;
}
=====================================
src/config/help.c
=====================================
@@ -254,15 +254,16 @@ static void print_desc(const char *str, unsigned margin, bool color)
fputs(TS_BLUE_BOLD, stdout);
const char *word = str;
- int wordlen = 0, wordwidth = 0;
+ size_t wordlen = 0;
+ int wordwidth = 0;
unsigned offset = 0;
bool newline = true;
while (str[0])
{
uint32_t cp;
- size_t charlen = vlc_towc(str, &cp);
- if (unlikely(charlen == (size_t)-1))
+ ssize_t charlen = vlc_towc(str, &cp);
+ if (unlikely(charlen == -1))
break;
int charwidth = wcwidth(cp);
@@ -316,11 +317,11 @@ static int vlc_swidth(const char *str)
for (int total = 0;;)
{
uint32_t cp;
- size_t charlen = vlc_towc(str, &cp);
+ ssize_t charlen = vlc_towc(str, &cp);
if (charlen == 0)
return total;
- if (charlen == (size_t)-1)
+ if (charlen == -1)
return -1;
str += charlen;
=====================================
src/input/es_out.c
=====================================
@@ -3396,11 +3396,12 @@ static int EsOutVaControlLocked( es_out_t *out, input_source_t *source,
}
input_thread_private_t *priv = input_priv(p_sys->p_input);
+#ifdef ENABLE_SOUT
if ( priv->p_sout != NULL )
{
sout_StreamSetPCR( priv->p_sout, i_pcr );
}
-
+#endif
/* TODO do not use vlc_tick_now() but proper stream acquisition date */
const bool b_low_delay = priv->b_low_delay;
bool b_extra_buffering_allowed = !b_low_delay && EsOutIsExtraBufferingAllowed( out );
=====================================
src/test/utf8.c
=====================================
@@ -29,13 +29,13 @@
#include <stdlib.h>
#include <stdbool.h>
-static void test_towc(const char *in, size_t want_len, uint32_t want_cp)
+static void test_towc(const char *in, ssize_t want_len, uint32_t want_cp)
{
uint32_t cp;
- size_t len;
+ ssize_t len;
- if (want_len != (size_t)-1)
- printf("\"%s\" is U+%04"PRIX32" (%zu bytes)\n", in, want_cp, want_len);
+ if (want_len != -1)
+ printf("\"%s\" is U+%04"PRIX32" (%zd bytes)\n", in, want_cp, want_len);
else
printf("Invalid sequence of %zu bytes\n", strlen(in));
@@ -47,7 +47,7 @@ static void test_towc(const char *in, size_t want_len, uint32_t want_cp)
exit(1);
}
- if (len != (size_t)-1 && want_cp != cp)
+ if (len != -1 && want_cp != cp)
{
printf(" ERROR: code point mismatch: %04"PRIX32"\n", cp);
exit(1);
=====================================
src/text/strings.c
=====================================
@@ -289,7 +289,7 @@ void vlc_xml_decode( char *psz_value )
char *vlc_xml_encode (const char *str)
{
struct vlc_memstream stream;
- size_t n;
+ ssize_t n;
uint32_t cp;
assert(str != NULL);
@@ -297,7 +297,7 @@ char *vlc_xml_encode (const char *str)
while ((n = vlc_towc (str, &cp)) != 0)
{
- if (unlikely(n == (size_t)-1))
+ if (unlikely(n == -1))
{
if (vlc_memstream_close(&stream) == 0)
free(stream.ptr);
=====================================
src/text/unicode.c
=====================================
@@ -112,7 +112,7 @@ int utf8_fprintf( FILE *stream, const char *fmt, ... )
return res;
}
-size_t vlc_towc (const char *str, uint32_t *restrict pwc)
+ssize_t vlc_towc (const char *str, uint32_t *restrict pwc)
{
assert (str != NULL);
@@ -214,6 +214,8 @@ char *vlc_strcasestr (const char *haystack, const char *needle)
}
s = vlc_towc (haystack, &(uint32_t) { 0 });
+ if (unlikely(s < 0))
+ return NULL;
haystack += s;
}
while (s > 0);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/984ccfa60e3fe154b173889c770b10196d04a0ce...d14929e83ac1d0fa06532a5d1745b18e9b215b96
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/984ccfa60e3fe154b173889c770b10196d04a0ce...d14929e83ac1d0fa06532a5d1745b18e9b215b96
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list