Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling unit tests for MSVC compiler + fix MSVC compiler and static analyzer warnings #5

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ if (BUILD_LIBRARY)
endif (BUILD_LIBRARY)

add_subdirectory("src")
if (NOT MSVC)
# There are linking errors when building tests under MSVC right now.
add_subdirectory("test")
endif (NOT MSVC)

if (MSVC)
# On Windows gtest uses Static CRT by default. This option fixes linking problems.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif (MSVC)

add_subdirectory("test")
8 changes: 4 additions & 4 deletions include/webvttxx/cue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public:
}

inline Direction direction() const {
return (Direction)cue->settings.vertical;
return static_cast<Direction>(cue->settings.vertical);
}
inline float relativeLinePosition() const {
return ( 1.f / 100.f ) * static_cast<float>(
Expand All @@ -138,14 +138,14 @@ public:
}
inline int lineNumber() const { return cue->settings.line; }
inline float textPosition() const {
return ( 1.f / 100.f ) * (float)cue->settings.position;
return static_cast<float>(( 1.0 / 100.0 ) * cue->settings.position);
}
inline uint textPositionPercentage() const { return cue->settings.position; }
inline float size() const {
return ( 1.f / 100.f ) * (float)cue->settings.size;
return static_cast<float>(( 1.0 / 100.0 ) * cue->settings.size);
}
inline uint sizePercentage() const { return cue->settings.size; }
inline Align alignment() const { return (Align)(cue->settings.align); }
inline Align alignment() const { return static_cast<Align>(cue->settings.align); }

inline bool isHorizontal() const { return orientation() == Horizontal; }
inline bool isVertical() const { return orientation() == Vertical; }
Expand Down
2 changes: 1 addition & 1 deletion include/webvttxx/node
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public:
~Node() { webvtt_release_node( &node ); }

bool isEmpty() const { return kind() == Empty; }
NodeKind kind() const { return (NodeKind)node->kind; }
NodeKind kind() const { return static_cast<NodeKind>(node->kind); }
int childCount() const { return node->data.internal_data->length; }

Node operator[]( int index )
Expand Down
6 changes: 3 additions & 3 deletions include/webvttxx/string
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public:
}

static uint32 toUtf32( uint16 low, uint16 high ) {
return (( uint32 )high << 10) + low - 0x35FDC00;
return ( high << uint32{ 10 }) + low - 0x35FDC00;
}

static uint32 toUtf32( uint16 ch ) {
if( !isSurrogate( ch ) ) {
return ( uint32 )ch;
return ch;
}
return 0xFFFD;
}
Expand All @@ -139,7 +139,7 @@ public:

/* Count of Unicode codepoints in string */
inline uint charCount() const {
return (uint)webvtt_utf8_chcount( utf8(), utf8() + length() );
return static_cast<uint>(webvtt_utf8_chcount( utf8(), utf8() + length() ));
}

inline String &append( char ch, webvtt_status &result ) {
Expand Down
12 changes: 6 additions & 6 deletions src/webvtt/cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ webvtt_cue_set_line( webvtt_cue *cue, const char *value )
return WEBVTT_BAD_LINE;
}

if( ( c = strchr( value, '%' ) ) && ( ( c[1] != '\0' ) || *value == '-' ) ) {
if( (( c = strchr( value, '%' ) ) != NULL) && ( ( c[1] != '\0' ) || *value == '-' ) ) {
/**
* 4. If any character in value other than the last character is a U+0025
* PERCENT SIGN character (%), then jump to the step labeled next setting.
Expand Down Expand Up @@ -279,7 +279,7 @@ webvtt_cue_set_position( webvtt_cue *cue, const char *value )
* 3. If any character in value other than the last character is a U+0025
* PERCENT SIGN character (%), then jump to the step labeled next setting.
*/
if( ( c = strchr( value, '%' ) ) && ( c[1] != '\0' ) ) {
if( (( c = strchr( value, '%' ) ) != NULL) && ( c[1] != '\0' ) ) {
return WEBVTT_BAD_POSITION;
}

Expand Down Expand Up @@ -351,7 +351,7 @@ webvtt_cue_set_size( webvtt_cue *cue, const char *value )
* 3. If any character in value other than the last character is a U+0025
* PERCENT SIGN character (%), then jump to the step labeled next setting.
*/
if( ( c = strchr( value, '%' ) ) && ( c[1] != '\0' ) ) {
if( (( c = strchr( value, '%' ) ) != NULL) && ( c[1] != '\0' ) ) {
return WEBVTT_BAD_SIZE;
}

Expand Down Expand Up @@ -470,7 +470,7 @@ webvtt_cue_set_setting_from_string( webvtt_cue *cue, const char *word )
return WEBVTT_BAD_CUESETTING;
}

idx = ( value - word ) - 1;
idx = (int)(( value - word ) - 1);
if( idx > 31 ) {
return WEBVTT_BAD_CUESETTING;
}
Expand All @@ -495,8 +495,8 @@ webvtt_cue_validate_set_settings( webvtt_parser self, webvtt_cue *cue,
return WEBVTT_INVALID_PARAM;
}
length = (int)webvtt_string_length( settings );
if( ( eol = strchr( webvtt_string_text( settings ), '\r' ) )
|| ( eol = strchr( webvtt_string_text( settings ), '\n' ) ) ) {
if( (( eol = strchr( webvtt_string_text( settings ), '\r' ) ) != NULL)
|| (( eol = strchr( webvtt_string_text( settings ), '\n' ) ) != NULL) ) {
length = (int)( eol - webvtt_string_text( settings ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/webvtt/cuetext.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ webvtt_parse_cuetext( webvtt_parser self, webvtt_cue *cue,
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-parsing-rules
*/
while( *position != '\0' ) {
webvtt_status status = WEBVTT_SUCCESS;
status = WEBVTT_SUCCESS;
webvtt_delete_token( &token );

/* Step 7. */
Expand Down
2 changes: 1 addition & 1 deletion src/webvtt/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const char *errstr[] = {
WEBVTT_EXPORT const char *
webvtt_strerror( webvtt_error err )
{
if( err >= (sizeof(errstr) / sizeof(*errstr)) ) {
if( err >= (sizeof(errstr) / sizeof(*errstr)) || (err < 0)) {
return "";
}
return errstr[ err ];
Expand Down
10 changes: 5 additions & 5 deletions src/webvtt/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ webvtt_ref_node( webvtt_node *node )
WEBVTT_EXPORT void
webvtt_init_node( webvtt_node **node )
{
if( *node != &empty_node ) {
if( node && *node ) {
if( node && *node != &empty_node ) {
if( *node ) {
webvtt_release_node( node );
}
*node = &empty_node;
Expand All @@ -66,7 +66,7 @@ webvtt_create_node( webvtt_node **node, webvtt_node_kind kind,
return WEBVTT_INVALID_PARAM;
}

if( !( temp_node = (webvtt_node *)webvtt_alloc0(sizeof(*temp_node)) ) )
if( ( temp_node = (webvtt_node *)webvtt_alloc0(sizeof(*temp_node)) ) == NULL )
{
return WEBVTT_OUT_OF_MEMORY;
}
Expand All @@ -92,8 +92,8 @@ webvtt_create_internal_node( webvtt_node **node, webvtt_node *parent,
return status;
}

if ( !( node_data =
(webvtt_internal_node_data *)webvtt_alloc0( sizeof(*node_data) ) ) )
if ( ( node_data =
(webvtt_internal_node_data *)webvtt_alloc0( sizeof(*node_data) ) ) == NULL )
{
return WEBVTT_OUT_OF_MEMORY;
}
Expand Down
19 changes: 11 additions & 8 deletions src/webvtt/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ webvtt_create_parser( webvtt_cue_fn on_read,
return WEBVTT_INVALID_PARAM;
}

if( !( p = ( webvtt_parser )webvtt_alloc0( sizeof * p ) ) ) {
if( ( p = ( webvtt_parser )webvtt_alloc0( sizeof * p ) ) == NULL ) {
return WEBVTT_OUT_OF_MEMORY;
}

Expand Down Expand Up @@ -303,7 +303,7 @@ do_push( webvtt_parser self, webvtt_uint token, webvtt_uint back,
{
if( STACK_SIZE + 1 >= self->stack_alloc ) {
webvtt_state *stack =
( webvtt_state * )webvtt_alloc0( sizeof( webvtt_state ) *
( webvtt_state * )webvtt_alloc0( (webvtt_uint)sizeof( webvtt_state ) *
( self->stack_alloc << 1 ) ), *tmp;
if( !stack ) {
ERROR( WEBVTT_ALLOCATION_FAILED );
Expand Down Expand Up @@ -495,6 +495,7 @@ WEBVTT_INTERN webvtt_status
webvtt_proc_cueline( webvtt_parser self, webvtt_cue *cue,
webvtt_string *line )
{
SAFE_ASSERT( cue != NULL );
const char *text;
webvtt_uint length;
DIE_IF( line == NULL );
Expand Down Expand Up @@ -580,7 +581,7 @@ parse_webvtt( webvtt_parser self, const char *buffer, webvtt_uint *ppos,
if( SP->flags == 0 ) {
int v;
if( ( v = webvtt_string_getline( &SP->v.text, buffer, &pos, len, 0,
finish ) ) ) {
finish ) ) != 0 ) {
if( v < 0 ) {
webvtt_release_string( &SP->v.text );
SP->type = V_NONE;
Expand All @@ -604,9 +605,9 @@ parse_webvtt( webvtt_parser self, const char *buffer, webvtt_uint *ppos,
}
}
if( SP->flags ) {
webvtt_token token = webvtt_lex_newline( self, buffer, &pos, len,
webvtt_token t = webvtt_lex_newline( self, buffer, &pos, len,
self->finished );
if( token == NEWLINE ) {
if( t == NEWLINE ) {
POP();
continue;
}
Expand Down Expand Up @@ -712,6 +713,7 @@ parse_webvtt( webvtt_parser self, const char *buffer, webvtt_uint *ppos,
* T_BODY state.
*/
POPBACK();
SP->state = T_BODY;
PUSH0( T_EOL, 1, V_INTEGER );
break;
default:
Expand Down Expand Up @@ -840,7 +842,7 @@ webvtt_read_cuetext( webvtt_parser self, const char *b,
webvtt_cue *cue;

/* Ensure that we have a cue to work with */
SAFE_ASSERT( self->top->type = V_CUE );
SAFE_ASSERT( self->top->type == V_CUE );
cue = self->top->v.cue;

/**
Expand All @@ -857,7 +859,7 @@ webvtt_read_cuetext( webvtt_parser self, const char *b,
if( !flags ) {
int v;
if( ( v = webvtt_string_getline( &self->line_buffer, b, &pos, len,
&self->truncate, finish ) ) ) {
&self->truncate, finish ) ) != 0 ) {
if( v < 0 || WEBVTT_FAILED( webvtt_string_putc( &self->line_buffer,
'\n' ) ) ) {
ERROR( WEBVTT_ALLOCATION_FAILED );
Expand All @@ -882,6 +884,7 @@ webvtt_read_cuetext( webvtt_parser self, const char *b,
self->token_pos = 0;
self->line++;

SAFE_ASSERT(self->line_buffer.d);
/* Remove the '\n' that we appended to determine that we're in state 1
*/
self->line_buffer.d->text[ --self->line_buffer.d->length ] = 0;
Expand Down Expand Up @@ -1062,7 +1065,7 @@ webvtt_parse_int( const char **pb, int *pdigits )
/**
* Digit character, carry on
*/
result = result * 10 + ( ch - '0' );
result = result * 10 + ( (webvtt_int64)ch - '0' );
++digits;
} else if( mul == 1 && digits == 0 && ch == '-' ) {
mul = -1;
Expand Down
Loading