@@ -774,81 +774,91 @@ static bool video_shader_parse_pass(config_file_t *conf,
774774static bool video_shader_parse_textures (config_file_t * conf ,
775775 struct video_shader * shader )
776776{
777- char * textures = (char * )malloc (1024 + PATH_MAX_LENGTH );
778-
779- if (!textures )
780- return false;
777+ char textures [1024 ];
778+ const char * id = NULL ;
779+ const char * next = NULL ;
781780
782781 textures [0 ] = '\0' ;
783782
784- if (config_get_array (conf , "textures" , textures , 1024 ))
783+ if (!config_get_array (conf , "textures" , textures , sizeof (textures )))
784+ return true;
785+
786+ for (id = textures ; id && * id && shader -> luts < GFX_MAX_TEXTURES ; id = next )
785787 {
788+ size_t id_len ;
789+ char id_buf [64 ];
790+ char idx [64 ];
786791 char texture_path [PATH_MAX_LENGTH ];
787- const char * id = NULL ;
788- char * save = NULL ;
792+ bool mipmap = false;
793+ bool smooth = false;
794+ struct config_entry_list * entry = NULL ;
789795
790- texture_path [0 ] = '\0' ;
791-
792- for (id = strtok_r (textures , ";" , & save );
793- id && shader -> luts < GFX_MAX_TEXTURES ;
794- shader -> luts ++ , id = strtok_r (NULL , ";" , & save ))
796+ /* Find the next semicolon delimiter */
797+ next = strchr (id , ';' );
798+ if (next )
795799 {
796- size_t _len ;
797- char idx [ 64 ];
798- bool mipmap = false;
799- bool smooth = false;
800- struct config_entry_list * entry = NULL ;
800+ id_len = ( size_t )( next - id ) ;
801+ next ++ ; /* skip past ';' */
802+ }
803+ else
804+ id_len = strlen ( id ) ;
801805
802- idx [0 ] = '\0' ;
806+ /* Skip empty tokens */
807+ if (id_len == 0 )
808+ continue ;
803809
804- if ( !(entry = config_get_entry (conf , id ))
805- || string_is_empty (entry -> value ))
806- {
807- RARCH_ERR ("[Shaders] Cannot find path to texture \"%s\".\n" ,
808- id );
809- free (textures );
810- return false;
811- }
810+ /* Copy token into a null-terminated buffer */
811+ if (id_len >= sizeof (id_buf ))
812+ id_len = sizeof (id_buf ) - 1 ;
813+ memcpy (id_buf , id , id_len );
814+ id_buf [id_len ] = '\0' ;
815+
816+ texture_path [0 ] = '\0' ;
812817
813- config_get_path (conf , id , texture_path , sizeof (texture_path ));
818+ if ( !(entry = config_get_entry (conf , id_buf ))
819+ || string_is_empty (entry -> value ))
820+ {
821+ RARCH_ERR ("[Shaders] Cannot find path to texture \"%s\".\n" ,
822+ id_buf );
823+ return false;
824+ }
814825
815- /* Get the absolute path and replace wildcards in the path */
816- fill_pathname_expanded_and_absolute (shader -> lut [shader -> luts ].path ,
817- PATH_MAX_LENGTH , conf -> path , texture_path );
818- /* TODO/FIXME - dehardcode PATH_MAX_LENGTH */
819- video_shader_replace_wildcards (shader -> lut [shader -> luts ].path ,
820- PATH_MAX_LENGTH , conf -> path );
826+ config_get_path (conf , id_buf , texture_path , sizeof (texture_path ));
821827
822- strlcpy (shader -> lut [shader -> luts ].id , id ,
823- sizeof (shader -> lut [shader -> luts ].id ));
828+ fill_pathname_expanded_and_absolute (shader -> lut [shader -> luts ].path ,
829+ PATH_MAX_LENGTH , conf -> path , texture_path );
830+ video_shader_replace_wildcards (shader -> lut [shader -> luts ].path ,
831+ PATH_MAX_LENGTH , conf -> path );
824832
825- _len = strlcpy (idx , id , sizeof (idx ));
833+ strlcpy (shader -> lut [shader -> luts ].id , id_buf ,
834+ sizeof (shader -> lut [shader -> luts ].id ));
826835
827- strlcpy (idx + _len , "_linear" , sizeof (idx ) - _len );
828- if (config_get_bool (conf , idx , & smooth ))
829- shader -> lut [shader -> luts ].filter = smooth
830- ? RARCH_FILTER_LINEAR
831- : RARCH_FILTER_NEAREST ;
832- else
833- shader -> lut [shader -> luts ].filter = RARCH_FILTER_UNSPEC ;
836+ strlcpy (idx , id_buf , sizeof (idx ));
834837
835- strlcpy (idx + _len , "_mipmap" , sizeof (idx ) - _len );
836- if (config_get_bool (conf , idx , & mipmap ))
837- shader -> lut [shader -> luts ].mipmap = mipmap ;
838- else
839- shader -> lut [shader -> luts ].mipmap = false;
838+ strlcpy (idx + id_len , "_linear" , sizeof (idx ) - id_len );
839+ if (config_get_bool (conf , idx , & smooth ))
840+ shader -> lut [shader -> luts ].filter = smooth
841+ ? RARCH_FILTER_LINEAR
842+ : RARCH_FILTER_NEAREST ;
843+ else
844+ shader -> lut [shader -> luts ].filter = RARCH_FILTER_UNSPEC ;
840845
841- strlcpy (idx + _len , "_wrap_mode" , sizeof (idx ) - _len );
842- entry = NULL ;
843- if ((entry = config_get_entry (conf , idx ))
844- && !string_is_empty (entry -> value ))
845- shader -> lut [shader -> luts ].wrap = video_shader_wrap_str_to_mode (entry -> value );
846- entry = NULL ;
846+ strlcpy (idx + id_len , "_mipmap" , sizeof (idx ) - id_len );
847+ if (config_get_bool (conf , idx , & mipmap ))
848+ shader -> lut [shader -> luts ].mipmap = mipmap ;
849+ else
850+ shader -> lut [shader -> luts ].mipmap = false;
847851
848- }
852+ strlcpy (idx + id_len , "_wrap_mode" , sizeof (idx ) - id_len );
853+ entry = NULL ;
854+ if ( (entry = config_get_entry (conf , idx ))
855+ && !string_is_empty (entry -> value ))
856+ shader -> lut [shader -> luts ].wrap = video_shader_wrap_str_to_mode (entry -> value );
857+ entry = NULL ;
858+
859+ shader -> luts ++ ;
849860 }
850861
851- free (textures );
852862 return true;
853863}
854864
0 commit comments