Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sratom_fix-utf8-string-size.patch 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 9d5ddba1337babab9e684b770eed923f96208e19 Mon Sep 17 00:00:00 2001
  2. From: Hanspeter Portner <dev@open-music-kontrollers.ch>
  3. Date: Thu, 11 Feb 2016 20:21:11 +0100
  4. Subject: [PATCH] Fix UTF-8 string size in 'read_node'
  5. 'sord_node_get_string_counted' returns character count, which then is used
  6. to forge strings and literals. But the character count is different from
  7. raw string size for strings containing multi-byte UTF-8 characters. Better
  8. use 'strlen' to get the raw byte size of the strings to be forged,
  9. if not, strings with multi-byte UTF-8 characters are truncatedly forged.
  10. ---
  11. src/sratom.c | 12 ++++++++----
  12. tests/sratom_test.c | 28 ++++++++++++++++++++++++++--
  13. 2 files changed, 34 insertions(+), 6 deletions(-)
  14. diff --git a/src/sratom.c b/src/sratom.c
  15. index e0996c4..fdb4893 100644
  16. --- a/src/sratom.c
  17. +++ b/src/sratom.c
  18. @@ -591,7 +591,8 @@ read_node(Sratom* sratom,
  19. lv2_atom_forge_write(forge, body, size);
  20. free(body);
  21. } else if (!strcmp(type_uri, LV2_ATOM__Path)) {
  22. - lv2_atom_forge_path(forge, str, len);
  23. + const size_t str_len = str ? strlen(str) : 0;
  24. + lv2_atom_forge_path(forge, str, str_len);
  25. } else if (!strcmp(type_uri, LV2_MIDI__MidiEvent)) {
  26. lv2_atom_forge_atom(forge, len / 2, sratom->midi_MidiEvent);
  27. for (const char* s = str; s < str + len; s += 2) {
  28. @@ -602,8 +603,9 @@ read_node(Sratom* sratom,
  29. }
  30. lv2_atom_forge_pad(forge, len / 2);
  31. } else {
  32. + const size_t str_len = str ? strlen(str) : 0;
  33. lv2_atom_forge_literal(
  34. - forge, str, len,
  35. + forge, str, str_len,
  36. sratom->map->map(sratom->map->handle, type_uri),
  37. 0);
  38. }
  39. @@ -611,13 +613,15 @@ read_node(Sratom* sratom,
  40. const char* prefix = "http://lexvo.org/id/iso639-3/";
  41. const size_t lang_len = strlen(prefix) + strlen(language);
  42. char* lang_uri = (char*)calloc(lang_len + 1, 1);
  43. + const size_t str_len = str ? strlen(str) : 0;
  44. snprintf(lang_uri, lang_len + 1, "%s%s", prefix, language);
  45. lv2_atom_forge_literal(
  46. - forge, str, len, 0,
  47. + forge, str, str_len, 0,
  48. sratom->map->map(sratom->map->handle, lang_uri));
  49. free(lang_uri);
  50. } else {
  51. - lv2_atom_forge_string(forge, str, len);
  52. + const size_t str_len = str ? strlen(str) : 0;
  53. + lv2_atom_forge_string(forge, str, str_len);
  54. }
  55. } else if (sord_node_get_type(node) == SORD_URI &&
  56. !(sratom->object_mode == SRATOM_OBJECT_MODE_BLANK_SUBJECT