5
5
//
6
6
7
7
//
8
- // version 0.9.9: Replace atof() with custom parser.
9
- // version 0.9.8: Fix multi-materials(per-face material ID).
10
- // version 0.9.7: Support multi-materials(per-face material ID) per
8
+ // version 0.9.10: Fix seg fault on windows.
9
+ // version 0.9.9 : Replace atof() with custom parser.
10
+ // version 0.9.8 : Fix multi-materials(per-face material ID).
11
+ // version 0.9.7 : Support multi-materials(per-face material ID) per
11
12
// object/group.
12
- // version 0.9.6: Support Ni(index of refraction) mtl parameter.
13
- // Parse transmittance material parameter correctly.
14
- // version 0.9.5: Parse multiple group name.
15
- // Add support of specifying the base path to load material file.
16
- // version 0.9.4: Initial suupport of group tag(g)
17
- // version 0.9.3: Fix parsing triple 'x/y/z'
18
- // version 0.9.2: Add more .mtl load support
19
- // version 0.9.1: Add initial .mtl load support
20
- // version 0.9.0: Initial
13
+ // version 0.9.6 : Support Ni(index of refraction) mtl parameter.
14
+ // Parse transmittance material parameter correctly.
15
+ // version 0.9.5 : Parse multiple group name.
16
+ // Add support of specifying the base path to load material file.
17
+ // version 0.9.4 : Initial suupport of group tag(g)
18
+ // version 0.9.3 : Fix parsing triple 'x/y/z'
19
+ // version 0.9.2 : Add more .mtl load support
20
+ // version 0.9.1 : Add initial .mtl load support
21
+ // version 0.9.0 : Initial
21
22
//
22
23
23
24
#include < cstdlib>
36
37
37
38
namespace tinyobj {
38
39
40
+ #define TINYOBJ_SSCANF_BUFFER_SIZE (4096 )
41
+
39
42
struct vertex_index {
40
43
int v_idx, vt_idx, vn_idx;
41
44
vertex_index (){};
@@ -457,10 +460,10 @@ std::string LoadMtl(std::map<std::string, int> &material_map,
457
460
InitMaterial (material);
458
461
459
462
// set new mtl name
460
- char namebuf[4096 ];
463
+ char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
461
464
token += 7 ;
462
465
#ifdef _MSC_VER
463
- sscanf_s (token, " %s" , namebuf);
466
+ sscanf_s (token, " %s" , namebuf, _countof (namebuf) );
464
467
#else
465
468
sscanf (token, " %s" , namebuf);
466
469
#endif
@@ -748,10 +751,10 @@ std::string LoadObj(std::vector<shape_t> &shapes,
748
751
// use mtl
749
752
if ((0 == strncmp (token, " usemtl" , 6 )) && isSpace ((token[6 ]))) {
750
753
751
- char namebuf[4096 ];
754
+ char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
752
755
token += 7 ;
753
756
#ifdef _MSC_VER
754
- sscanf_s (token, " %s" , namebuf);
757
+ sscanf_s (token, " %s" , namebuf, _countof (namebuf) );
755
758
#else
756
759
sscanf (token, " %s" , namebuf);
757
760
#endif
@@ -775,10 +778,10 @@ std::string LoadObj(std::vector<shape_t> &shapes,
775
778
776
779
// load mtl
777
780
if ((0 == strncmp (token, " mtllib" , 6 )) && isSpace ((token[6 ]))) {
778
- char namebuf[4096 ];
781
+ char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
779
782
token += 7 ;
780
783
#ifdef _MSC_VER
781
- sscanf_s (token, " %s" , namebuf);
784
+ sscanf_s (token, " %s" , namebuf, _countof (namebuf) );
782
785
#else
783
786
sscanf (token, " %s" , namebuf);
784
787
#endif
@@ -841,10 +844,10 @@ std::string LoadObj(std::vector<shape_t> &shapes,
841
844
shape = shape_t ();
842
845
843
846
// @todo { multiple object name? }
844
- char namebuf[4096 ];
847
+ char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
845
848
token += 2 ;
846
849
#ifdef _MSC_VER
847
- sscanf_s (token, " %s" , namebuf);
850
+ sscanf_s (token, " %s" , namebuf, _countof (namebuf) );
848
851
#else
849
852
sscanf (token, " %s" , namebuf);
850
853
#endif
0 commit comments