]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/utils.cpp
Fix warnings about certain narrowing conversions not being allowed in C++11
[libs/core.git] / source / strings / utils.cpp
index fff6cdb290362cb724b96b61c29f68c5970dfe0c..a67eb15b1f4b2b738fecc1b40bc60e7e9e3a97f3 100644 (file)
@@ -253,7 +253,9 @@ string c_escape(const string &str, bool escape_8bit)
                        result += "\\\\";
                else if(static_cast<unsigned char>(*i)<' ' || (escape_8bit && (*i&0x80)))
                {
-                       char buf[4] = {'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)};
+                       char buf[4] = { '\\', 0 };
+                       for(unsigned j=0; j<3; ++j)
+                               buf[1+j] = '0'+((static_cast<unsigned char>(*i)>>(6-j*3))&7);
                        result.append(buf, 4);
                }
                else