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.
This commit is contained in:
Nicolas Guillemot
2015-08-08 16:20:57 -07:00
parent 870ead273e
commit 191a7dfdc8

View File

@@ -469,7 +469,7 @@ std::string LoadMtl(std::map<std::string, int> &material_map,
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE]; char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
token += 7; token += 7;
#ifdef _MSC_VER #ifdef _MSC_VER
sscanf_s(token, "%s", namebuf, _countof(namebuf)); sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
#else #else
sscanf(token, "%s", namebuf); sscanf(token, "%s", namebuf);
#endif #endif
@@ -767,7 +767,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE]; char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
token += 7; token += 7;
#ifdef _MSC_VER #ifdef _MSC_VER
sscanf_s(token, "%s", namebuf, _countof(namebuf)); sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
#else #else
sscanf(token, "%s", namebuf); sscanf(token, "%s", namebuf);
#endif #endif
@@ -796,7 +796,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE]; char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
token += 7; token += 7;
#ifdef _MSC_VER #ifdef _MSC_VER
sscanf_s(token, "%s", namebuf, _countof(namebuf)); sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
#else #else
sscanf(token, "%s", namebuf); sscanf(token, "%s", namebuf);
#endif #endif
@@ -862,7 +862,7 @@ std::string LoadObj(std::vector<shape_t> &shapes,
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE]; char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
token += 2; token += 2;
#ifdef _MSC_VER #ifdef _MSC_VER
sscanf_s(token, "%s", namebuf, _countof(namebuf)); sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
#else #else
sscanf(token, "%s", namebuf); sscanf(token, "%s", namebuf);
#endif #endif