@@ -156,18 +156,25 @@ namespace vix::middleware::parsers
156156 // keep only [a-zA-Z0-9._-]
157157 std::string out;
158158 out.reserve (s.size ());
159- for (unsigned char c : s)
159+
160+ for (char ch : s)
160161 {
161- if ((c >= ' a' && c <= ' z' ) ||
162- (c >= ' A' && c <= ' Z' ) ||
163- (c >= ' 0' && c <= ' 9' ) ||
164- c == ' .' || c == ' _' || c == ' -' )
162+ const unsigned char c = static_cast <unsigned char >(ch);
163+
164+ if ((c >= static_cast <unsigned char >(' a' ) && c <= static_cast <unsigned char >(' z' )) ||
165+ (c >= static_cast <unsigned char >(' A' ) && c <= static_cast <unsigned char >(' Z' )) ||
166+ (c >= static_cast <unsigned char >(' 0' ) && c <= static_cast <unsigned char >(' 9' )) ||
167+ c == static_cast <unsigned char >(' .' ) ||
168+ c == static_cast <unsigned char >(' _' ) ||
169+ c == static_cast <unsigned char >(' -' ))
165170 {
166171 out.push_back (static_cast <char >(c));
167172 }
168173 }
174+
169175 if (out.empty ())
170176 out = " file" ;
177+
171178 return out;
172179 }
173180
@@ -183,15 +190,17 @@ namespace vix::middleware::parsers
183190 inline std::string random_hex_8 ()
184191 {
185192 std::random_device rd;
186- std::uint32_t x = (std::uint32_t (rd ()) << 16 ) ^ std::uint32_t (rd ());
193+ std::uint32_t x = (static_cast <std::uint32_t >(rd ()) << 16 ) ^ static_cast <std::uint32_t >(rd ());
194+
187195 const char *hex = " 0123456789abcdef" ;
188- std::string out;
189- out. resize ( 8 );
190- for (int i = 7 ; i >= 0 ; --i )
196+
197+ std::string out ( 8 , ' \0 ' );
198+ for (std:: size_t i = out. size () ; i-- > 0 ;)
191199 {
192- out[i] = hex[x & 0xF ];
200+ out[i] = hex[static_cast <std:: size_t >( x & 0xF ) ];
193201 x >>= 4 ;
194202 }
203+
195204 return out;
196205 }
197206
0 commit comments