Skip to content

Commit d284ab0

Browse files
author
Marius Vlad
committed
pipewire,remoting,tests: Replace asprintf w/ str_printf
We have a string helper which wraps asprintf(). Uses that one because it clears out the destination string, but also it won't return the number of bytes unlinke asprintf(). Fixes warnings like: warning: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’. Signed-off-by: Marius Vlad <[email protected]>
1 parent 3e94836 commit d284ab0

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

pipewire/pipewire-plugin.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "backend.h"
3030
#include "libweston-internal.h"
3131
#include "shared/timespec-util.h"
32+
#include "shared/string-helpers.h"
3233
#include <libweston/backend-drm.h>
3334
#include <libweston/weston-log.h>
3435

@@ -550,7 +551,7 @@ pipewire_output_create(struct weston_compositor *c, char *name)
550551
output->pipewire = pipewire;
551552
wl_list_insert(pipewire->output_list.prev, &output->link);
552553

553-
asprintf(&remoting_name, "%s-%s", connector_name, name);
554+
str_printf(&remoting_name, "%s-%s", connector_name, name);
554555
weston_head_init(head, remoting_name);
555556
weston_head_set_subpixel(head, WL_OUTPUT_SUBPIXEL_NONE);
556557
weston_head_set_monitor_strings(head, make, model, serial_number);

remoting/remoting-plugin.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "shared/helpers.h"
4848
#include "shared/timespec-util.h"
4949
#include "shared/weston-drm-fourcc.h"
50+
#include "shared/string-helpers.h"
5051
#include "backend.h"
5152
#include "libweston-internal.h"
5253

@@ -777,7 +778,7 @@ remoting_output_create(struct weston_compositor *c, char *name)
777778
output->remoting = remoting;
778779
wl_list_insert(remoting->output_list.prev, &output->link);
779780

780-
asprintf(&remoting_name, "%s-%s", connector_name, name);
781+
str_printf(&remoting_name, "%s-%s", connector_name, name);
781782
weston_head_init(head, remoting_name);
782783
weston_head_set_subpixel(head, WL_OUTPUT_SUBPIXEL_NONE);
783784
weston_head_set_monitor_strings(head, make, model, serial_number);

tests/weston-test-fixture-compositor.c

+20-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <fcntl.h>
3939

4040
#include "shared/helpers.h"
41+
#include "shared/string-helpers.h"
4142
#include "weston-test-fixture-compositor.h"
4243
#include "weston.h"
4344
#include "test-config.h"
@@ -116,7 +117,8 @@ get_lock_path(void)
116117
return NULL;
117118
}
118119

119-
if (asprintf(&lock_path, "%s/%s", env_path, suffix) == -1)
120+
str_printf(&lock_path, "%s/%s", env_path, suffix);
121+
if (!lock_path)
120122
return NULL;
121123

122124
return lock_path;
@@ -345,10 +347,10 @@ execute_compositor(const struct compositor_setup *setup,
345347
prog_args_init(&args);
346348

347349
/* argv[0] */
348-
asprintf(&tmp, "weston-%s", setup->testset_name);
350+
str_printf(&tmp, "weston-%s", setup->testset_name);
349351
prog_args_take(&args, tmp);
350352

351-
asprintf(&tmp, "--backend=%s", backend_to_str(setup->backend));
353+
str_printf(&tmp, "--backend=%s", backend_to_str(setup->backend));
352354
prog_args_take(&args, tmp);
353355

354356
if (setup->backend == WESTON_BACKEND_DRM) {
@@ -362,7 +364,7 @@ execute_compositor(const struct compositor_setup *setup,
362364
ret = RESULT_SKIP;
363365
goto out;
364366
}
365-
asprintf(&tmp, "--drm-device=%s", drm_device);
367+
str_printf(&tmp, "--drm-device=%s", drm_device);
366368
prog_args_take(&args, tmp);
367369

368370
prog_args_take(&args, strdup("--seat=weston-test-seat"));
@@ -379,36 +381,36 @@ execute_compositor(const struct compositor_setup *setup,
379381
/* Test suite needs the debug protocol to be able to take screenshots */
380382
prog_args_take(&args, strdup("--debug"));
381383

382-
asprintf(&tmp, "--socket=%s", setup->testset_name);
384+
str_printf(&tmp, "--socket=%s", setup->testset_name);
383385
prog_args_take(&args, tmp);
384386

385-
asprintf(&tmp, "--modules=%s%s%s", TESTSUITE_PLUGIN_PATH,
386-
setup->extra_module ? "," : "",
387-
setup->extra_module ? setup->extra_module : "");
387+
str_printf(&tmp, "--modules=%s%s%s", TESTSUITE_PLUGIN_PATH,
388+
setup->extra_module ? "," : "",
389+
setup->extra_module ? setup->extra_module : "");
388390
prog_args_take(&args, tmp);
389391

390392
if (setup->backend != WESTON_BACKEND_DRM &&
391393
setup->backend != WESTON_BACKEND_FBDEV) {
392-
asprintf(&tmp, "--width=%d", setup->width);
394+
str_printf(&tmp, "--width=%d", setup->width);
393395
prog_args_take(&args, tmp);
394396

395-
asprintf(&tmp, "--height=%d", setup->height);
397+
str_printf(&tmp, "--height=%d", setup->height);
396398
prog_args_take(&args, tmp);
397399
}
398400

399401
if (setup->scale != 1) {
400-
asprintf(&tmp, "--scale=%d", setup->scale);
402+
str_printf(&tmp, "--scale=%d", setup->scale);
401403
prog_args_take(&args, tmp);
402404
}
403405

404406
if (setup->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
405-
asprintf(&tmp, "--transform=%s",
406-
transform_to_str(setup->transform));
407+
str_printf(&tmp, "--transform=%s",
408+
transform_to_str(setup->transform));
407409
prog_args_take(&args, tmp);
408410
}
409411

410412
if (setup->config_file) {
411-
asprintf(&tmp, "--config=%s", setup->config_file);
413+
str_printf(&tmp, "--config=%s", setup->config_file);
412414
prog_args_take(&args, tmp);
413415
free(setup->config_file);
414416
} else {
@@ -419,11 +421,11 @@ execute_compositor(const struct compositor_setup *setup,
419421
if (ctmp)
420422
prog_args_take(&args, strdup(ctmp));
421423

422-
asprintf(&tmp, "--shell=%s", shell_to_str(setup->shell));
424+
str_printf(&tmp, "--shell=%s", shell_to_str(setup->shell));
423425
prog_args_take(&args, tmp);
424426

425427
if (setup->logging_scopes) {
426-
asprintf(&tmp, "--logger-scopes=%s", setup->logging_scopes);
428+
str_printf(&tmp, "--logger-scopes=%s", setup->logging_scopes);
427429
prog_args_take(&args, tmp);
428430
}
429431

@@ -472,7 +474,8 @@ open_ini_file(struct compositor_setup *setup)
472474
wd = realpath(".", NULL);
473475
assert(wd);
474476

475-
if (asprintf(&tmp_path, "%s/%s.ini", wd, setup->testset_name) == -1) {
477+
str_printf(&tmp_path, "%s/%s.ini", wd, setup->testset_name);
478+
if (!tmp_path) {
476479
fprintf(stderr, "Fail formatting Weston.ini file name.\n");
477480
goto out;
478481
}

0 commit comments

Comments
 (0)