Skip to content

Commit 191a7df

Browse files
committed
fix sscanf_s buffer size type
Uses of sscanf_s give the following warnings in 64-bit builds: tiny_obj_loader.cc(471): warning C4477: 'sscanf_s' : format string '%s' requires an argument of type 'int', but variadic argument 2 has type 'unsigned __int64' tiny_obj_loader.cc(471): note: this argument is used as a buffer size This was fixed by casting the uses of _countof(namebuf) to unsigned, since the MSDN documentation for sscanf_s specifies that "The size parameter is of type **unsigned**, not **size_t**." (https://msdn.microsoft.com/en-us/library/t6z7bya3.aspx) This silences the warnings.
1 parent 870ead2 commit 191a7df

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎tiny_obj_loader.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ std::string LoadMtl(std::map<std::string, int> &material_map,
469469
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
470470
token += 7;
471471
#ifdef _MSC_VER
472-
sscanf_s(token, "%s", namebuf, _countof(namebuf));
472+
sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
473473
#else
474474
sscanf(token, "%s", namebuf);
475475
#endif
@@ -767,7 +767,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
767767
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
768768
token += 7;
769769
#ifdef _MSC_VER
770-
sscanf_s(token, "%s", namebuf, _countof(namebuf));
770+
sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
771771
#else
772772
sscanf(token, "%s", namebuf);
773773
#endif
@@ -796,7 +796,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
796796
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
797797
token += 7;
798798
#ifdef _MSC_VER
799-
sscanf_s(token, "%s", namebuf, _countof(namebuf));
799+
sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
800800
#else
801801
sscanf(token, "%s", namebuf);
802802
#endif
@@ -862,7 +862,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
862862
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
863863
token += 2;
864864
#ifdef _MSC_VER
865-
sscanf_s(token, "%s", namebuf, _countof(namebuf));
865+
sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
866866
#else
867867
sscanf(token, "%s", namebuf);
868868
#endif

0 commit comments

Comments
 (0)