0002-fix-detection-of-reallocarray.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. From 85ca67b9275780cc40bee08f92954db9184cad56 Mon Sep 17 00:00:00 2001
  2. From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  3. Date: Fri, 27 May 2022 15:00:17 +0200
  4. Subject: [PATCH] fix detection of reallocarray
  5. Fix detection of reallocarray (e.g. on glibc) raised since commit
  6. 0708a39b439cec2871cfe3b705191028397e5b8b
  7. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  8. [Retrieved (and backported) from:
  9. https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/85ca67b9275780cc40bee08f92954db9184cad56]
  10. ---
  11. meson.build | 1 +
  12. pipewire-jack/src/metadata.c | 2 +-
  13. spa/plugins/bluez5/bluez5-dbus.c | 5 +++++
  14. src/modules/module-client-node/client-node.c | 2 +-
  15. src/modules/module-client-node/remote-node.c | 4 ++--
  16. src/modules/module-client-node/v0/client-node.c | 4 ++--
  17. .../client-endpoint/endpoint-stream.c | 4 ++--
  18. .../module-session-manager/client-endpoint/endpoint.c | 4 ++--
  19. .../client-session/endpoint-link.c | 4 ++--
  20. .../module-session-manager/client-session/session.c | 4 ++--
  21. src/pipewire/introspect.c | 6 +++---
  22. src/pipewire/utils.c | 10 ++++++++++
  23. src/pipewire/utils.h | 5 ++---
  24. 13 files changed, 35 insertions(+), 20 deletions(-)
  25. diff --git a/meson.build b/meson.build
  26. index 314091779..e6bc29ba4 100644
  27. --- a/meson.build
  28. +++ b/meson.build
  29. @@ -375,6 +375,7 @@ check_functions = [
  30. ['gettid', '#include <unistd.h>', ['-D_GNU_SOURCE'], []],
  31. ['memfd_create', '#include <sys/mman.h>', ['-D_GNU_SOURCE'], []],
  32. ['getrandom', '#include <stddef.h>\n#include <sys/random.h>', ['-D_GNU_SOURCE'], []],
  33. + ['reallocarray', '#include <stdlib.h>', ['-D_GNU_SOURCE'], []],
  34. ['sigabbrev_np', '#include <string.h>', ['-D_GNU_SOURCE'], []],
  35. ['XSetIOErrorExitHandler', '#include <X11/Xlib.h>', [], [x11_dep]],
  36. ]
  37. diff --git a/pipewire-jack/src/metadata.c b/pipewire-jack/src/metadata.c
  38. index 8ccb5a348..d50948ff4 100644
  39. --- a/pipewire-jack/src/metadata.c
  40. +++ b/pipewire-jack/src/metadata.c
  41. @@ -120,7 +120,7 @@ static jack_property_t *add_property(jack_description_t *desc, const char *key,
  42. if (desc->property_cnt == desc->property_size) {
  43. ns = desc->property_size > 0 ? desc->property_size * 2 : 8;
  44. - np = reallocarray(desc->properties, ns, sizeof(*prop));
  45. + np = pw_reallocarray(desc->properties, ns, sizeof(*prop));
  46. if (np == NULL)
  47. return NULL;
  48. desc->property_size = ns;
  49. diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c
  50. index 98bf05df1..c2e4a7ba7 100644
  51. --- a/spa/plugins/bluez5/bluez5-dbus.c
  52. +++ b/spa/plugins/bluez5/bluez5-dbus.c
  53. @@ -50,6 +50,7 @@
  54. #include <spa/utils/string.h>
  55. #include <spa/utils/json.h>
  56. +#include "config.h"
  57. #include "codec-loader.h"
  58. #include "player.h"
  59. #include "defs.h"
  60. @@ -1579,7 +1580,11 @@ const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_
  61. if (j >= size) {
  62. const struct a2dp_codec **p;
  63. size = size * 2;
  64. +#ifdef HAVE_REALLOCARRRAY
  65. p = reallocarray(supported_codecs, size, sizeof(const struct a2dp_codec *));
  66. +#else
  67. + p = realloc(supported_codecs, size * sizeof(const struct a2dp_codec *));
  68. +#endif
  69. if (p == NULL) {
  70. free(supported_codecs);
  71. return NULL;
  72. diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c
  73. index 2533c360c..9357d03da 100644
  74. --- a/src/modules/module-client-node/client-node.c
  75. +++ b/src/modules/module-client-node/client-node.c
  76. @@ -191,7 +191,7 @@ static int update_params(struct params *p, uint32_t n_params, const struct spa_p
  77. p->params = NULL;
  78. } else {
  79. struct spa_pod **np;
  80. - np = reallocarray(p->params, p->n_params, sizeof(struct spa_pod *));
  81. + np = pw_reallocarray(p->params, p->n_params, sizeof(struct spa_pod *));
  82. if (np == NULL) {
  83. pw_log_error("%p: can't realloc: %m", p);
  84. free(p->params);
  85. diff --git a/src/modules/module-client-node/remote-node.c b/src/modules/module-client-node/remote-node.c
  86. index c04273e95..c0af9a21f 100644
  87. --- a/src/modules/module-client-node/remote-node.c
  88. +++ b/src/modules/module-client-node/remote-node.c
  89. @@ -318,7 +318,7 @@ static int add_node_update(struct node_data *data, uint32_t change_mask, uint32_
  90. id, &idx, NULL, &param, &b.b);
  91. if (res == 1) {
  92. void *p;
  93. - p = reallocarray(params, n_params + 1, sizeof(struct spa_pod *));
  94. + p = pw_reallocarray(params, n_params + 1, sizeof(struct spa_pod *));
  95. if (p == NULL) {
  96. res = -errno;
  97. pw_log_error("realloc failed: %m");
  98. @@ -384,7 +384,7 @@ static int add_port_update(struct node_data *data, struct pw_impl_port *port, ui
  99. id, &idx, NULL, &param, &b.b);
  100. if (res == 1) {
  101. void *p;
  102. - p = reallocarray(params, n_params + 1, sizeof(struct spa_pod*));
  103. + p = pw_reallocarray(params, n_params + 1, sizeof(struct spa_pod*));
  104. if (p == NULL) {
  105. res = -errno;
  106. pw_log_error("realloc failed: %m");
  107. diff --git a/src/modules/module-client-node/v0/client-node.c b/src/modules/module-client-node/v0/client-node.c
  108. index e71abbb14..aeb5931c6 100644
  109. --- a/src/modules/module-client-node/v0/client-node.c
  110. +++ b/src/modules/module-client-node/v0/client-node.c
  111. @@ -476,7 +476,7 @@ do_update_port(struct node *this,
  112. port->params = NULL;
  113. } else {
  114. void *p;
  115. - p = reallocarray(port->params, port->n_params, sizeof(struct spa_pod *));
  116. + p = pw_reallocarray(port->params, port->n_params, sizeof(struct spa_pod *));
  117. if (p == NULL) {
  118. pw_log_error("%p: port %u can't realloc: %m", this, port_id);
  119. free(port->params);
  120. @@ -1049,7 +1049,7 @@ client_node0_update(void *data,
  121. this->params = NULL;
  122. } else {
  123. void *p;
  124. - p = reallocarray(this->params, this->n_params, sizeof(struct spa_pod *));
  125. + p = pw_reallocarray(this->params, this->n_params, sizeof(struct spa_pod *));
  126. if (p == NULL) {
  127. pw_log_error("%p: can't realloc: %m", this);
  128. free(this->params);
  129. diff --git a/src/modules/module-session-manager/client-endpoint/endpoint-stream.c b/src/modules/module-session-manager/client-endpoint/endpoint-stream.c
  130. index 8d7f2da2b..8dde6f749 100644
  131. --- a/src/modules/module-session-manager/client-endpoint/endpoint-stream.c
  132. +++ b/src/modules/module-session-manager/client-endpoint/endpoint-stream.c
  133. @@ -196,7 +196,7 @@ int endpoint_stream_update(struct endpoint_stream *this,
  134. this->params = NULL;
  135. } else {
  136. void *p;
  137. - p = reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  138. + p = pw_reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  139. if (p == NULL) {
  140. free(this->params);
  141. this->params = NULL;
  142. @@ -227,7 +227,7 @@ int endpoint_stream_update(struct endpoint_stream *this,
  143. this->info.params = NULL;
  144. } else {
  145. void *p;
  146. - p = reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  147. + p = pw_reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  148. if (p == NULL) {
  149. free(this->info.params);
  150. this->info.params = NULL;
  151. diff --git a/src/modules/module-session-manager/client-endpoint/endpoint.c b/src/modules/module-session-manager/client-endpoint/endpoint.c
  152. index 8a7863ee1..aa13989b6 100644
  153. --- a/src/modules/module-session-manager/client-endpoint/endpoint.c
  154. +++ b/src/modules/module-session-manager/client-endpoint/endpoint.c
  155. @@ -213,7 +213,7 @@ int endpoint_update(struct endpoint *this,
  156. this->params = NULL;
  157. } else {
  158. void *p;
  159. - p = reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  160. + p = pw_reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  161. if (p == NULL) {
  162. free(this->params);
  163. this->params = NULL;
  164. @@ -245,7 +245,7 @@ int endpoint_update(struct endpoint *this,
  165. this->info.params = NULL;
  166. } else {
  167. void *p;
  168. - p = reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  169. + p = pw_reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  170. if (p == NULL) {
  171. free(this->info.params);
  172. this->info.params = NULL;
  173. diff --git a/src/modules/module-session-manager/client-session/endpoint-link.c b/src/modules/module-session-manager/client-session/endpoint-link.c
  174. index 9048fe30c..0bdbfc946 100644
  175. --- a/src/modules/module-session-manager/client-session/endpoint-link.c
  176. +++ b/src/modules/module-session-manager/client-session/endpoint-link.c
  177. @@ -209,7 +209,7 @@ int endpoint_link_update(struct endpoint_link *this,
  178. this->params = NULL;
  179. } else {
  180. void *p;
  181. - p = reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  182. + p = pw_reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  183. if (p == NULL) {
  184. free(this->params);
  185. this->params = NULL;
  186. @@ -241,7 +241,7 @@ int endpoint_link_update(struct endpoint_link *this,
  187. this->info.params = NULL;
  188. } else {
  189. void *p;
  190. - p = reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  191. + p = pw_reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  192. if (p == NULL) {
  193. free(this->info.params);
  194. this->info.params = NULL;
  195. diff --git a/src/modules/module-session-manager/client-session/session.c b/src/modules/module-session-manager/client-session/session.c
  196. index 681c56118..87c1b96a7 100644
  197. --- a/src/modules/module-session-manager/client-session/session.c
  198. +++ b/src/modules/module-session-manager/client-session/session.c
  199. @@ -196,7 +196,7 @@ int session_update(struct session *this,
  200. this->params = NULL;
  201. } else {
  202. void *p;
  203. - p = reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  204. + p = pw_reallocarray(this->params, n_params, sizeof(struct spa_pod*));
  205. if (p == NULL) {
  206. free(this->params);
  207. this->params = NULL;
  208. @@ -222,7 +222,7 @@ int session_update(struct session *this,
  209. this->info.params = NULL;
  210. } else {
  211. void *p;
  212. - p = reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  213. + p = pw_reallocarray(this->info.params, info->n_params, sizeof(struct spa_param_info));
  214. if (p == NULL) {
  215. free(this->info.params);
  216. this->info.params = NULL;
  217. diff --git a/src/pipewire/introspect.c b/src/pipewire/introspect.c
  218. index 35598a90d..2855009c0 100644
  219. --- a/src/pipewire/introspect.c
  220. +++ b/src/pipewire/introspect.c
  221. @@ -213,7 +213,7 @@ struct pw_node_info *pw_node_info_merge(struct pw_node_info *info,
  222. uint32_t i, user, n_params = update->n_params;
  223. void *np;
  224. - np = reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  225. + np = pw_reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  226. if (np == NULL) {
  227. free(info->params);
  228. info->params = NULL;
  229. @@ -283,7 +283,7 @@ struct pw_port_info *pw_port_info_merge(struct pw_port_info *info,
  230. uint32_t i, user, n_params = update->n_params;
  231. void *np;
  232. - np = reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  233. + np = pw_reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  234. if (np == NULL) {
  235. free(info->params);
  236. info->params = NULL;
  237. @@ -443,7 +443,7 @@ struct pw_device_info *pw_device_info_merge(struct pw_device_info *info,
  238. uint32_t i, user, n_params = update->n_params;
  239. void *np;
  240. - np = reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  241. + np = pw_reallocarray(info->params, n_params, sizeof(struct spa_param_info));
  242. if (np == NULL) {
  243. free(info->params);
  244. info->params = NULL;
  245. diff --git a/src/pipewire/utils.c b/src/pipewire/utils.c
  246. index 2f3240faf..a644049fd 100644
  247. --- a/src/pipewire/utils.c
  248. +++ b/src/pipewire/utils.c
  249. @@ -168,3 +168,13 @@ ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
  250. close(fd);
  251. return bytes;
  252. }
  253. +
  254. +SPA_EXPORT
  255. +void* pw_reallocarray(void *ptr, size_t nmemb, size_t size)
  256. +{
  257. +#ifdef HAVE_REALLOCARRAY
  258. + return reallocarray(ptr, nmemb, size);
  259. +#else
  260. + return realloc(ptr, nmemb * size);
  261. +#endif
  262. +}
  263. diff --git a/src/pipewire/utils.h b/src/pipewire/utils.h
  264. index 8f8e002b7..b320db22f 100644
  265. --- a/src/pipewire/utils.h
  266. +++ b/src/pipewire/utils.h
  267. @@ -88,6 +88,8 @@ pw_strip(char *str, const char *whitespace);
  268. ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags);
  269. +void* pw_reallocarray(void *ptr, size_t nmemb, size_t size);
  270. +
  271. /**
  272. * \}
  273. */
  274. --
  275. GitLab