Skip to content

Commit

Permalink
rework of assert in gpac - cf #2705
Browse files Browse the repository at this point in the history
- use gf_assert and gf_fatal_assert (will always kill the program)
- added -fatal-assert option to configure to force all asserts to be fatal
- added GPAC_ENABLE_DEBUG and GPAC_ASSERT_FATAL macros
- cleanup of several asserts in the process
  • Loading branch information
jeanlf committed Dec 21, 2023
1 parent d876710 commit 1234ebc
Show file tree
Hide file tree
Showing 219 changed files with 1,596 additions and 1,472 deletions.
7 changes: 3 additions & 4 deletions applications/gpac/compositor_tools.c
Expand Up @@ -792,10 +792,9 @@ Bool mp4c_event_proc(void *ptr, GF_Event *evt)
case GF_EVENT_AUTHORIZATION:
{
u32 nb_retry = 4;
assert( evt->type == GF_EVENT_AUTHORIZATION);
assert( evt->auth.user);
assert( evt->auth.password);
assert( evt->auth.site_url);
gf_fatal_assert( evt->auth.user);
gf_fatal_assert( evt->auth.password);
gf_assert( evt->auth.site_url);
while ((!strlen(evt->auth.user) || !strlen(evt->auth.password)) && (nb_retry > 0) ) {
nb_retry--;
fprintf(stderr, "**** Authorization required for site %s ****\n", evt->auth.site_url);
Expand Down
2 changes: 1 addition & 1 deletion applications/gpac/gpac_help.c
Expand Up @@ -3455,7 +3455,7 @@ Bool gpac_expand_alias(int o_argc, char **o_argv)
argv[a_idx] = o_argv[i];
a_idx++;
}
assert(argc==a_idx);
gf_assert(argc==a_idx);

for (i=0; i< (u32) argc; i++) {
char *arg = argv[i];
Expand Down
10 changes: 9 additions & 1 deletion configure
Expand Up @@ -121,7 +121,7 @@ is_emcfg="no"
has_remotery="yes"
em_type="js"
em_size="0"

fatal_assert="no"

#flags not set by generic lib config
has_x11="no"
Expand Down Expand Up @@ -381,6 +381,7 @@ GPAC build options:
--enable-gprof enable profiling
--enable-gcov enable coverage
--enable-pic enable Position Independant Code for shared objects
--fatal-assert make any call to assert abort program
--strip enable strip
--std-allocator uses standard lib memory allocator
--enable-sanitizer enable address sanitizer
Expand Down Expand Up @@ -636,6 +637,8 @@ for opt do
;;
--enable-afl-clang) cc_orig="afl-clang"; cxx_orig="afl-clang++"
;;
--fatal-assert) fatal_assert="yes";
;;
--verbose) verbose="yes";
;;
--static-bin) static_bin="yes"
Expand Down Expand Up @@ -2747,6 +2750,11 @@ fi

fi

if test "$fatal_assert" = "yes" ; then
echo "#define GPAC_ASSERT_FATAL" >> $TMPH
fi


echo "HAS_OPENSSL=$has_ssl" >> config.mak
if test "$has_ssl" != "no" ; then
echo "#define GPAC_HAS_SSL" >> $TMPH
Expand Down
9 changes: 8 additions & 1 deletion include/gpac/rtp_streamer.h
Expand Up @@ -151,7 +151,14 @@ typedef struct
const char *netcap_id;
} GF_RTPStreamerConfig;

GF_RTPStreamer *gf_rtp_streamer_new_ex(const GF_RTPStreamerConfig *cfg, Bool for_rtsp);
/*!
\brief RTP Streamer constructor with extended parameters
Constructs a new RTP file streamer
\param cfg configuration of the streamer
\param for_rtsp indicates this is an RTP channel in an RTSP session, RTP channel will not be created, use \ref gf_rtp_streamer_init_rtsp
\return a new RTP streamer, or NULL of error or not supported
*/GF_RTPStreamer *gf_rtp_streamer_new_ex(const GF_RTPStreamerConfig *cfg, Bool for_rtsp);

/*!
\brief RTP file streamer destructor
Expand Down
37 changes: 37 additions & 0 deletions include/gpac/setup.h
Expand Up @@ -819,6 +819,43 @@ void* gf_realloc(void *ptr, size_t size);
*/
size_t gf_strlcpy(char *dst, const char *src, size_t dsize);

#ifdef GPAC_ASSERT_FATAL
/*! fatal error assert, will always kill the program if condition is false
\param _cond condition to test
*/
#define gf_fatal_assert(_cond) if (! (_cond)) { fprintf(stderr, "Fatal error " #_cond " file %s line %d, exiting\n", (strstr(__FILE__, "gpac") ? strstr(__FILE__, "gpac") + 5 : __FILE__), __LINE__ ); exit(3); }
/*! error assert, will assert if condition is false but will not always kill the program
\param _cond condition to test
*/
#define gf_assert(_cond) gf_fatal_assert(_cond)
#elif defined(NDEBUG)
//! @cond Doxygen_Suppress
#define gf_assert(_cond)
#define gf_fatal_assert(_cond) if (! (_cond)) { fprintf(stderr, "Fatal error " #_cond " file %s line %d, exiting\n", (strstr(__FILE__, "gpac") ? strstr(__FILE__, "gpac") + 5 : __FILE__), __LINE__ ); exit(3); }
//! @endcond
#else
//! @cond Doxygen_Suppress
#define gf_assert(_cond) assert(_cond)
#define gf_fatal_assert(_cond) assert(_cond)
//! @endcond
#endif

#if defined(_DEBUG)
#ifdef NDEBUG
#undef NDEBUG
#endif
#endif

#if defined(NDEBUG)
#ifdef GPAC_ENABLE_DEBUG
#undef GPAC_ENABLE_DEBUG
#endif
#else
#ifndef GPAC_ENABLE_DEBUG
#define GPAC_ENABLE_DEBUG
#endif
#endif

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions modules/dx_hw/dx_audio.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2012
* Copyright (c) Telecom ParisTech 2000-2023
* All rights reserved
*
* This file is part of GPAC / DirectX audio and video render module
Expand Down Expand Up @@ -312,7 +312,7 @@ void DS_FillBuffer(GF_AudioOutput *dr, u32 buffer)
return;
}

assert(size == ctx->buffer_size);
gf_assert(size == ctx->buffer_size);

dr->FillBuffer(dr->audio_renderer, pLock, size);

Expand Down
5 changes: 1 addition & 4 deletions modules/ft_font/ft_font.c
Expand Up @@ -95,8 +95,6 @@ static const char * BEST_SANS_FONTS[] = {
*/
static Bool isBestFontFor(const char * listOfFonts[], const char * currentBestFont, const char * fontName) {
u32 i;
assert( fontName );
assert( listOfFonts );
for (i = 0 ; listOfFonts[i]; i++) {
const char * best = listOfFonts[i];
if (!stricmp(best, fontName))
Expand Down Expand Up @@ -255,6 +253,7 @@ static void ft_rescan_fonts(GF_FontReader *dr)
const char *opt;
char fkey[GF_MAX_PATH];
const char *key = gf_opts_get_key_name("FontCache", i);
if (!key) continue;
opt = gf_opts_get_key("FontCache", key);
if (!strchr(opt, '/') && !strchr(opt, '\\')) continue;

Expand Down Expand Up @@ -832,8 +831,6 @@ static void ft_delete(GF_BaseInterface *ifce)
if (ftpriv->font_sans) gf_free(ftpriv->font_sans);
if (ftpriv->font_fixed) gf_free(ftpriv->font_fixed);
if (ftpriv->font_default) gf_free(ftpriv->font_default);
assert(!gf_list_count(ftpriv->loaded_fonts) );

gf_list_del(ftpriv->loaded_fonts);

gf_free(dr->udta);
Expand Down
5 changes: 2 additions & 3 deletions modules/sdl_out/sdl_out.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2012
* Copyright (c) Telecom ParisTech 2000-2023
* All rights reserved
*
* This file is part of GPAC / SDL audio and video module
Expand Down Expand Up @@ -51,8 +51,7 @@ Bool SDLOUT_InitSDL()
void SDLOUT_CloseSDL()
{
if (!is_init) return;
assert(num_users);
num_users--;
if (num_users) num_users--;
if (!num_users)
SDL_Quit();
return;
Expand Down
22 changes: 10 additions & 12 deletions modules/sdl_out/video.c
Expand Up @@ -467,6 +467,8 @@ GF_Err SDLVid_ResizeWindow(GF_VideoOutput *dr, u32 width, u32 height)
SDLVID();
GF_Event evt;

if (!width || !height) return GF_BAD_PARAM;

/*lock X mutex to make sure the event queue is not being processed*/
gf_mx_p(ctx->evt_mx);

Expand Down Expand Up @@ -507,9 +509,6 @@ GF_Err SDLVid_ResizeWindow(GF_VideoOutput *dr, u32 width, u32 height)
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, nb_bits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, nb_bits);

assert(width);
assert(height);

#if SDL_VERSION_ATLEAST(2,0,0)
if (ctx->hidden)
flags |= SDL_WINDOW_HIDDEN;
Expand Down Expand Up @@ -776,12 +775,11 @@ static Bool SDLVid_InitializeWindow(SDLVidCtx *ctx, GF_VideoOutput *dr)
{
SDL_Rect** modes;
modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
assert( (modes != (SDL_Rect**)0));
if ( modes == (SDL_Rect**)-1 ) {
fprintf(stderr, "SDL : DONT KNOW WHICH MODE TO USE, using 640x480\n");
dr->max_screen_width = 640;
dr->max_screen_height = 480;
} else {
} else if (modes) {
int i;
dr->max_screen_width = 0;
for (i=0; modes[i]; ++i) {
Expand Down Expand Up @@ -992,14 +990,14 @@ Bool SDLVid_ProcessMessageQueue(SDLVidCtx *ctx, GF_VideoOutput *dr)
case SDL_TEXTINPUT: /* Since SDL 1.3, text-input is handled in a specific event */
{
u32 len = (u32) strlen( sdl_evt.text.text);
u32 ucs4_len;
assert( len < 5 );
ucs4_len = utf8_to_ucs4 (&(gpac_evt.character.unicode_char), len, (unsigned char*)(sdl_evt.text.text));
if (ucs4_len) {
gpac_evt.type = GF_EVENT_TEXTINPUT;
dr->on_event(dr->evt_cbk_hdl, &gpac_evt);
if (len < 5 ) {
gpac_evt.character.window_id = dr->window_id;
u32 ucs4_len = utf8_to_ucs4 (&(gpac_evt.character.unicode_char), len, (unsigned char*)(sdl_evt.text.text));
if (ucs4_len) {
gpac_evt.type = GF_EVENT_TEXTINPUT;
dr->on_event(dr->evt_cbk_hdl, &gpac_evt);
}
}
gpac_evt.character.window_id = dr->window_id;
break;
}
#endif /* SDL_TEXTINPUTEVENT_TEXT_SIZE */
Expand Down
2 changes: 1 addition & 1 deletion share/doc/idl/nodejs.idl
Expand Up @@ -295,7 +295,7 @@ boolean is_supported_source(DOMString url, DOMString parent=null);

\note Custom filters are always created with the flag GF_FS_REG_MAIN_THREAD set, so that they always run in the main thread

\note If the custom filter is a source, it must be initially scheduled using \ref reschedule
\note If the custom filter is a source, it must be initially scheduled using reschedule

\param name name for the filter
\param flags filter flags
Expand Down
25 changes: 13 additions & 12 deletions src/bifs/bifs_codec.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2012
* Copyright (c) Telecom ParisTech 2000-2023
* All rights reserved
*
* This file is part of GPAC / BIFS codec sub-project
Expand Down Expand Up @@ -130,19 +130,18 @@ GF_Err gf_bifs_decoder_configure_stream(GF_BifsDecoder * codec, u16 ESID, u8 *De
Bool new_cfg = GF_FALSE;
GF_Err e;

if (!codec) return GF_BAD_PARAM;
if (!DecoderSpecificInfo) {
if (!codec->streamInfo) return GF_BAD_PARAM;
/* Hack for T-DMB non compliant streams */
GF_SAFEALLOC(pInfo, BIFSStreamInfo);
if (!pInfo) return GF_OUT_OF_MEM;
pInfo->ESID = ESID;
pInfo->config.PixelMetrics = GF_TRUE;
pInfo->config.version = (objectTypeIndication==2) ? 1 : 2;
assert( codec );
assert( codec->streamInfo );
return gf_list_add(codec->streamInfo, pInfo);
}

assert( codec );
pInfo = gf_bifs_dec_get_stream(codec, ESID);
//we allow reconfigure of the BIFS stream
if (pInfo == NULL) {
Expand Down Expand Up @@ -172,7 +171,7 @@ GF_Err gf_bifs_decoder_configure_stream(GF_BifsDecoder * codec, u16 ESID, u8 *De
}
gf_bs_del(bs);

assert( codec->streamInfo );
gf_assert( codec->streamInfo );
//first stream, configure size
if (!codec->ignore_size && !gf_list_count(codec->streamInfo)) {
gf_sg_set_scene_size_info(codec->scenegraph, pInfo->config.Width, pInfo->config.Height, pInfo->config.PixelMetrics);
Expand Down Expand Up @@ -225,7 +224,7 @@ void command_buffers_del(GF_List *command_buffers)
GF_EXPORT
void gf_bifs_decoder_del(GF_BifsDecoder *codec)
{
assert(gf_list_count(codec->QPs)==0);
gf_assert(gf_list_count(codec->QPs)==0);
gf_list_del(codec->QPs);

/*destroy all config*/
Expand Down Expand Up @@ -293,9 +292,11 @@ GF_Err gf_bifs_decode_au(GF_BifsDecoder *codec, u16 ESID, const u8 *data, u32 da

GF_Node *gf_bifs_enc_find_node(GF_BifsEncoder *codec, u32 nodeID)
{
if (codec->current_proto_graph) return gf_sg_find_node(codec->current_proto_graph, nodeID);
assert(codec->scene_graph);
return gf_sg_find_node(codec->scene_graph, nodeID);
if (codec->current_proto_graph)
return gf_sg_find_node(codec->current_proto_graph, nodeID);
if (codec->scene_graph)
return gf_sg_find_node(codec->scene_graph, nodeID);
return NULL;
}


Expand Down Expand Up @@ -328,7 +329,7 @@ static BIFSStreamInfo *BE_GetStream(GF_BifsEncoder * codec, u16 ESID)
GF_EXPORT
void gf_bifs_encoder_del(GF_BifsEncoder *codec)
{
assert(gf_list_count(codec->QPs)==0);
gf_assert(gf_list_count(codec->QPs)==0);
gf_list_del(codec->QPs);
/*destroy all config*/
while (gf_list_count(codec->streamInfo)) {
Expand Down Expand Up @@ -501,14 +502,14 @@ GF_Err gf_bifs_encoder_set_source_url(GF_BifsEncoder *codec, const char *src_url
GF_EXPORT
u32 gf_bifs_get_child_table(GF_Node *Node)
{
assert(Node);
if (!Node) return 0;
return gf_sg_mpeg4_node_get_child_ndt(Node);
}


GF_Err gf_bifs_get_field_index(GF_Node *Node, u32 inField, u8 IndexMode, u32 *allField)
{
assert(Node);
if (!Node) return GF_BAD_PARAM;
switch (Node->sgprivate->tag) {
case TAG_ProtoNode:
return gf_sg_proto_get_field_ind_static(Node, inField, IndexMode, allField);
Expand Down
6 changes: 3 additions & 3 deletions src/bifs/com_dec.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2012
* Copyright (c) Telecom ParisTech 2000-2023
* All rights reserved
*
* This file is part of GPAC / BIFS codec sub-project
Expand Down Expand Up @@ -1074,7 +1074,7 @@ GF_Err gf_bifs_dec_proto_list(GF_BifsDecoder * codec, GF_BitStream *bs, GF_List
if (codec->info->config.UsePredictiveMFField) {
f = gf_bs_read_int(bs, 1);
/*predictive encoding of proto field is not possible since QP info is not present yet*/
assert(!f);
gf_assert(!f);
}
/*reserved*/
f = gf_bs_read_int(bs, 1);
Expand Down Expand Up @@ -1107,7 +1107,7 @@ GF_Err gf_bifs_dec_proto_list(GF_BifsDecoder * codec, GF_BitStream *bs, GF_List

if (codec->info->config.UsePredictiveMFField) {
flag = gf_bs_read_int(bs, 1);
assert(!flag);
gf_assert(!flag);
}
/*reserved*/
gf_bs_read_int(bs, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/bifs/conditional.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2012
* Copyright (c) Telecom ParisTech 2000-2023
* All rights reserved
*
* This file is part of GPAC / BIFS codec sub-project
Expand Down Expand Up @@ -68,7 +68,7 @@ static void Conditional_execute(M_Conditional *node)
/*set the codec working graph to the node one (to handle conditional in protos)*/
prev_graph = priv->codec->current_graph;
priv->codec->current_graph = gf_node_get_graph((GF_Node*)node);
assert(priv->codec->current_graph);
if (!priv->codec->current_graph) return;

priv->codec->info = priv->info;
prevproto = priv->codec->pCurrentProto;
Expand Down

0 comments on commit 1234ebc

Please sign in to comment.