diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-29 21:54:08 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-03-29 22:11:08 -0400 |
commit | 849c3515abff7033dbd4723fd7328cb07af74222 (patch) | |
tree | 879dde1271572fdfe86dc0f33944100ba61a959e | |
parent | Fix failure to rearrange output in some cases (diff) | |
download | sway-849c3515abff7033dbd4723fd7328cb07af74222.tar.gz sway-849c3515abff7033dbd4723fd7328cb07af74222.tar.zst sway-849c3515abff7033dbd4723fd7328cb07af74222.zip |
Use statically allocated text buffer
-rw-r--r-- | common/pango.c | 6 | ||||
-rw-r--r-- | sway/commands/bar.c | 6 |
2 files changed, 5 insertions, 7 deletions
diff --git a/common/pango.c b/common/pango.c index 212d96cf..2ae7883c 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -32,7 +32,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
32 | 32 | ||
33 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 33 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, |
34 | int32_t scale, bool markup, const char *fmt, ...) { | 34 | int32_t scale, bool markup, const char *fmt, ...) { |
35 | char *buf = malloc(2048); | 35 | static char buf[2048]; |
36 | 36 | ||
37 | va_list args; | 37 | va_list args; |
38 | va_start(args, fmt); | 38 | va_start(args, fmt); |
@@ -45,12 +45,11 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
45 | pango_cairo_update_layout(cairo, layout); | 45 | pango_cairo_update_layout(cairo, layout); |
46 | pango_layout_get_pixel_size(layout, width, height); | 46 | pango_layout_get_pixel_size(layout, width, height); |
47 | g_object_unref(layout); | 47 | g_object_unref(layout); |
48 | free(buf); | ||
49 | } | 48 | } |
50 | 49 | ||
51 | void pango_printf(cairo_t *cairo, const char *font, | 50 | void pango_printf(cairo_t *cairo, const char *font, |
52 | int32_t scale, bool markup, const char *fmt, ...) { | 51 | int32_t scale, bool markup, const char *fmt, ...) { |
53 | char *buf = malloc(2048); | 52 | static char buf[2048]; |
54 | 53 | ||
55 | va_list args; | 54 | va_list args; |
56 | va_start(args, fmt); | 55 | va_start(args, fmt); |
@@ -63,5 +62,4 @@ void pango_printf(cairo_t *cairo, const char *font, | |||
63 | pango_cairo_update_layout(cairo, layout); | 62 | pango_cairo_update_layout(cairo, layout); |
64 | pango_cairo_show_layout(cairo, layout); | 63 | pango_cairo_show_layout(cairo, layout); |
65 | g_object_unref(layout); | 64 | g_object_unref(layout); |
66 | free(buf); | ||
67 | } | 65 | } |
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 548106b3..ff111163 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -36,15 +36,15 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | // set bar id | 38 | // set bar id |
39 | int i; | 39 | for (int i = 0; i < config->bars->length; ++i) { |
40 | for (i = 0; i < config->bars->length; ++i) { | ||
41 | if (bar == config->bars->items[i]) { | 40 | if (bar == config->bars->items[i]) { |
42 | const int len = 5 + numlen(i); // "bar-" + i + \0 | 41 | const int len = 5 + numlen(i); // "bar-" + i + \0 |
43 | bar->id = malloc(len * sizeof(char)); | 42 | bar->id = malloc(len * sizeof(char)); |
44 | if (bar->id) { | 43 | if (bar->id) { |
45 | snprintf(bar->id, len, "bar-%d", i); | 44 | snprintf(bar->id, len, "bar-%d", i); |
46 | } else { | 45 | } else { |
47 | return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID"); | 46 | return cmd_results_new(CMD_FAILURE, |
47 | "bar", "Unable to allocate bar ID"); | ||
48 | } | 48 | } |
49 | break; | 49 | break; |
50 | } | 50 | } |