Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
f1725a8f by Steve Lhomme at 2026-01-30T14:40:05+00:00
memstream: make the error handling private
We can use a special value in length to signal an error internally.
The length (and pointer) are only supposed to be valid on success.
- - - - -
2 changed files:
- include/vlc_memstream.h
- src/text/memstream.c
Changes:
=====================================
include/vlc_memstream.h
=====================================
@@ -39,11 +39,7 @@
*/
struct vlc_memstream
{
- union
- {
- FILE *stream;
- int error;
- };
+ FILE *stream;
char *ptr; /**< Buffer start address */
size_t length; /**< Buffer length in bytes */
};
=====================================
src/text/memstream.c
=====================================
@@ -118,28 +118,31 @@ int vlc_memstream_vprintf(struct vlc_memstream *ms, const
char *fmt,
int vlc_memstream_open(struct vlc_memstream *ms)
{
- ms->error = 0;
ms->ptr = calloc(1, 1);
if (unlikely(ms->ptr == NULL))
- ms->error = EOF;
+ {
+ ms->length = SIZE_MAX;
+ return EOF;
+ }
ms->length = 0;
- return ms->error;
+ return 0;
}
int vlc_memstream_flush(struct vlc_memstream *ms)
{
- return ms->error;
+ return ms->length == SIZE_MAX ? EOF : 0;
}
int vlc_memstream_close(struct vlc_memstream *ms)
{
- if (ms->error)
+ if (ms->length == SIZE_MAX)
{
free(ms->ptr);
ms->ptr = NULL;
+ return EOF;
}
- return ms->error;
-}
+ return 0;
+}
size_t vlc_memstream_write(struct vlc_memstream *ms, const void *ptr,
size_t len)
@@ -164,7 +167,7 @@ size_t vlc_memstream_write(struct vlc_memstream *ms, const
void *ptr,
return len;
error:
- ms->error = EOF;
+ ms->length = SIZE_MAX;
return 0;
}
@@ -206,7 +209,7 @@ int vlc_memstream_vprintf(struct vlc_memstream *ms, const
char *fmt,
return len;
error:
- ms->error = EOF;
+ ms->length = SIZE_MAX;
return EOF;
}
#endif
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/commit/f1725a8f5f6f1e411bf53e4b10535f13af417d4b
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/commit/f1725a8f5f6f1e411bf53e4b10535f13af417d4b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits