Commit 63dc59cc authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

utils: Fix string copying

parent 5f1f016f
......@@ -280,7 +280,9 @@ struct traits<NPString>
NULL_TO_NPVARIANT( v );
return;
}
auto raw = strdup( s.UTF8Characters );
auto raw = static_cast<NPUTF8*>( NPN_MemAlloc( s.UTF8Length + 1 ) );
memcpy( raw, s.UTF8Characters, s.UTF8Length );
raw[s.UTF8Length] = 0;
STRINGZ_TO_NPVARIANT( raw, v );
}
};
......@@ -305,7 +307,9 @@ struct traits<NPUTF8*>
NULL_TO_NPVARIANT( v );
return;
}
auto copy = strdup( str );
auto len = strlen(str);
auto copy = static_cast<NPUTF8*>( NPN_MemAlloc( len + 1 ) );
strcpy(copy, str);
STRINGZ_TO_NPVARIANT( copy, v );
}
};
......@@ -325,8 +329,7 @@ struct traits<std::string>
static void from( const std::string& str, NPVariant& v )
{
auto copy = strdup( str.c_str() );
STRINGZ_TO_NPVARIANT( copy, v );
traits<char*>::from( str.c_str(), v );
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment