libnm: only call strlen() once in NMSetting8021x:path_to_scheme_value()

Also assert that path is not empty.
This commit is contained in:
Thomas Haller 2015-02-26 02:27:54 +01:00
parent 88a79625a6
commit 11371b5470
2 changed files with 14 additions and 9 deletions

View file

@ -572,13 +572,16 @@ static GBytes *
path_to_scheme_value (const char *path)
{
GByteArray *array;
gsize len;
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (path != NULL && path[0], NULL);
/* Add the path scheme tag to the front, then the fielname */
array = g_byte_array_sized_new (strlen (path) + strlen (SCHEME_PATH) + 1);
len = strlen (path);
/* Add the path scheme tag to the front, then the filename */
array = g_byte_array_sized_new (len + strlen (SCHEME_PATH) + 1);
g_byte_array_append (array, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH));
g_byte_array_append (array, (const guint8 *) path, strlen (path));
g_byte_array_append (array, (const guint8 *) path, len);
g_byte_array_append (array, (const guint8 *) "\0", 1);
return g_byte_array_free_to_bytes (array);

View file

@ -551,14 +551,16 @@ static GByteArray *
path_to_scheme_value (const char *path)
{
GByteArray *array;
gsize len;
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (path != NULL && path[0], NULL);
/* Add the path scheme tag to the front, then the fielname */
array = g_byte_array_sized_new (strlen (path) + strlen (SCHEME_PATH) + 1);
g_assert (array);
len = strlen (path);
/* Add the path scheme tag to the front, then the filename */
array = g_byte_array_sized_new (len + strlen (SCHEME_PATH) + 1);
g_byte_array_append (array, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH));
g_byte_array_append (array, (const guint8 *) path, strlen (path));
g_byte_array_append (array, (const guint8 *) path, len);
g_byte_array_append (array, (const guint8 *) "\0", 1);
return array;
}