Browse Source

use string_view instead of string in to_utf8() to avoid copying.

afl-fuzzing
Roker 3 years ago
parent
commit
f825639553
2 changed files with 6 additions and 6 deletions
  1. +4
    -4
      src/to_utf8.cc
  2. +2
    -2
      src/to_utf8.hh

+ 4
- 4
src/to_utf8.cc View File

@ -64,14 +64,14 @@ namespace
static const size_t IconvBufSize = 64;
std::string to_utf8_iconv(const std::string& charset, const std::string& s)
std::string to_utf8_iconv(const sv& charset, const std::string& s)
{
iconv_t ict = iconv_open("UTF-8", charset.c_str());
iconv_t ict = iconv_open("UTF-8", charset.data());
if(ict == (iconv_t)-1)
{
if(errno==EINVAL)
{
throw std::runtime_error("Cannot convert from charset \"" + charset + "\" to UTF-8.");
throw std::runtime_error("Cannot convert from charset \"" + std::string(charset) + "\" to UTF-8.");
}else{
throw std::runtime_error(std::string("Internal error: ") + strerror(errno) );
}
@ -113,7 +113,7 @@ std::string to_utf8_iconv(const std::string& charset, const std::string& s)
} // end of anonymous namespace
std::string to_utf8( const std::string& charset, const std::string& s)
std::string to_utf8( const sv& charset, const std::string& s)
{
std::string charset_upper{charset};
boost::algorithm::to_upper(charset_upper);


+ 2
- 2
src/to_utf8.hh View File

@ -1,8 +1,8 @@
#ifndef PEP_MIME_TO_UTF8_HH
#define PEP_MIME_TO_UTF8_HH
#include <string>
#include "pEpMIME_internal.hh"
std::string to_utf8( const std::string& charset, const std::string& s);
std::string to_utf8( const sv& charset, const std::string& s);
#endif // PEP_MIME_TO_UTF8_HH

Loading…
Cancel
Save