@@ -1032,11 +1032,7 @@ void LoadMtl(std::map<std::string, int> *material_map,
10321032 // set new mtl name
10331033 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
10341034 token += 7 ;
1035- #ifdef _MSC_VER
1036- sscanf_s (token, " %s" , namebuf, (unsigned )_countof (namebuf));
1037- #else
1038- std::sscanf (token, " %s" , namebuf);
1039- #endif
1035+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
10401036 material.name = namebuf;
10411037 continue ;
10421038 }
@@ -1543,11 +1539,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
15431539 if ((0 == strncmp (token, " usemtl" , 6 )) && IS_SPACE ((token[6 ]))) {
15441540 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
15451541 token += 7 ;
1546- #ifdef _MSC_VER
1547- sscanf_s (token, " %s" , namebuf, (unsigned )_countof (namebuf));
1548- #else
1549- std::sscanf (token, " %s" , namebuf);
1550- #endif
1542+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
15511543
15521544 int newMaterialId = -1 ;
15531545 if (material_map.find (namebuf) != material_map.end ()) {
@@ -1663,11 +1655,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
16631655 // @todo { multiple object name? }
16641656 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
16651657 token += 2 ;
1666- #ifdef _MSC_VER
1667- sscanf_s (token, " %s" , namebuf, (unsigned )_countof (namebuf));
1668- #else
1669- std::sscanf (token, " %s" , namebuf);
1670- #endif
1658+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
16711659 name = std::string (namebuf);
16721660
16731661 continue ;
@@ -1678,11 +1666,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
16781666
16791667 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
16801668 token += 2 ;
1681- #ifdef _MSC_VER
1682- sscanf_s (token, " %s" , namebuf, (unsigned )_countof (namebuf));
1683- #else
1684- std::sscanf (token, " %s" , namebuf);
1685- #endif
1669+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
16861670 tag.name = std::string (namebuf);
16871671
16881672 token += tag.name .size () + 1 ;
@@ -1706,12 +1690,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
17061690 for (size_t i = 0 ; i < static_cast <size_t >(ts.num_strings ); ++i) {
17071691 char stringValueBuffer[TINYOBJ_SSCANF_BUFFER_SIZE ];
17081692
1709- #ifdef _MSC_VER
1710- sscanf_s (token, " %s" , stringValueBuffer,
1711- (unsigned )_countof (stringValueBuffer));
1712- #else
1713- std::sscanf (token, " %s" , stringValueBuffer);
1714- #endif
1693+ std::snprintf (stringValueBuffer, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
17151694 tag.stringValues [i] = stringValueBuffer;
17161695 token += tag.stringValues [i].size () + 1 ;
17171696 }
@@ -1853,12 +1832,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
18531832 if ((0 == strncmp (token, " usemtl" , 6 )) && IS_SPACE ((token[6 ]))) {
18541833 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
18551834 token += 7 ;
1856- #ifdef _MSC_VER
1857- sscanf_s (token, " %s" , namebuf,
1858- static_cast <unsigned int >(_countof (namebuf)));
1859- #else
1860- std::sscanf (token, " %s" , namebuf);
1861- #endif
1835+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
18621836
18631837 int newMaterialId = -1 ;
18641838 if (material_map.find (namebuf) != material_map.end ()) {
@@ -1968,11 +1942,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
19681942 // @todo { multiple object name? }
19691943 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE ];
19701944 token += 2 ;
1971- #ifdef _MSC_VER
1972- sscanf_s (token, " %s" , namebuf, (unsigned )_countof (namebuf));
1973- #else
1974- std::sscanf (token, " %s" , namebuf);
1975- #endif
1945+ std::snprintf (namebuf, TINYOBJ_SSCANF_BUFFER_SIZE , " %s" , token);
19761946 std::string object_name = std::string (namebuf);
19771947
19781948 if (callback.object_cb ) {
@@ -1988,11 +1958,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
19881958
19891959 char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
19901960 token += 2;
1991- #ifdef _MSC_VER
1992- sscanf_s(token, "%s", namebuf, (unsigned)_countof(namebuf));
1993- #else
1994- std::sscanf(token, "%s", namebuf);
1995- #endif
1961+ std::snprintf(namebuf, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
19961962 tag.name = std::string(namebuf);
19971963
19981964 token += tag.name.size() + 1;
@@ -2016,12 +1982,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
20161982 for (size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
20171983 char stringValueBuffer[TINYOBJ_SSCANF_BUFFER_SIZE];
20181984
2019- #ifdef _MSC_VER
2020- sscanf_s(token, "%s", stringValueBuffer,
2021- (unsigned)_countof(stringValueBuffer));
2022- #else
2023- std::sscanf(token, "%s", stringValueBuffer);
2024- #endif
1985+ std::snprintf(stringValueBuffer, TINYOBJ_SSCANF_BUFFER_SIZE, "%s", token);
20251986 tag.stringValues[i] = stringValueBuffer;
20261987 token += tag.stringValues[i].size() + 1;
20271988 }
0 commit comments