summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-11 02:45:02 +0100
committerDavid Robillard <d@drobilla.net>2021-01-11 13:34:44 +0100
commit0577775e418250ba696337ab4137f6ae2c244afa (patch)
tree7773dc68f1769e732caa36e63bad014994e40c50
parentbf75193a3f0ab1fa01e579ea59df75419db26b61 (diff)
downloadsratom-0577775e418250ba696337ab4137f6ae2c244afa.tar.gz
sratom-0577775e418250ba696337ab4137f6ae2c244afa.tar.bz2
sratom-0577775e418250ba696337ab4137f6ae2c244afa.zip
Avoid use of snprintf for simple string copying
-rw-r--r--src/sratom.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/sratom.c b/src/sratom.c
index b0a0aa4..692257d 100644
--- a/src/sratom.c
+++ b/src/sratom.c
@@ -676,10 +676,15 @@ read_literal(Sratom* sratom, LV2_Atom_Forge* forge, const SordNode* node)
forge, str, len, sratom->map->map(sratom->map->handle, type_uri), 0);
}
} else if (language) {
- const char* prefix = "http://lexvo.org/id/iso639-3/";
- const size_t lang_len = strlen(prefix) + strlen(language);
- char* lang_uri = (char*)calloc(lang_len + 1, 1);
- snprintf(lang_uri, lang_len + 1, "%s%s", prefix, language);
+ static const char* const prefix = "http://lexvo.org/id/iso639-3/";
+ const size_t prefix_len = strlen(prefix);
+ const size_t language_len = strlen(language);
+ const size_t lang_uri_len = prefix_len + language_len;
+ char* lang_uri = (char*)calloc(lang_uri_len + 1, 1);
+
+ memcpy(lang_uri, prefix, prefix_len + 1);
+ memcpy(lang_uri + prefix_len, language, language_len + 1);
+
lv2_atom_forge_literal(
forge, str, len, 0, sratom->map->map(sratom->map->handle, lang_uri));
free(lang_uri);