~adnano/wmenu-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH] Fix crash when an input line contains %

Details
Message ID
<CAKA5H008HZhT2rVSV1RV9Y41nWLZ+Hvu7Vyn6ocq-mc5rfUhcQ@mail.gmail.com>
DKIM signature
pass
Download raw message
Hi,

I've made a fix for a segmentation fault that happens when one of the
input lines contains '%' character.

---
 main.c  | 10 +++++-----
 pango.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c
index 496521f..f651fe6 100644
--- a/main.c
+++ b/main.c
@@ -110,7 +110,7 @@ int render_text(struct menu_state *state, cairo_t
*cairo, const char *str,
  int left_padding, int right_padding) {

  int text_width, text_height;
- get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
+ get_text_size(cairo, state->font, &text_width, &text_height, NULL,
1, "%s", str);
  int text_y = (state->line_height / 2.0) - (text_height / 2.0);

  if (background) {
@@ -133,7 +133,7 @@ int render_horizontal_item(struct menu_state
*state, cairo_t *cairo, const char
  int left_padding, int right_padding) {

  int text_width, text_height;
- get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
+ get_text_size(cairo, state->font, &text_width, &text_height, NULL,
1, "%s", str);
  int text_y = (state->line_height / 2.0) - (text_height / 2.0);

  if (x + left_padding + text_width > width) {
@@ -148,7 +148,7 @@ int render_horizontal_item(struct menu_state
*state, cairo_t *cairo, const char

  cairo_move_to(cairo, x + left_padding, y + text_y);
  cairo_set_source_u32(cairo, foreground);
- pango_printf(cairo, state->font, 1, str);
+ pango_printf(cairo, state->font, 1, "%s", str);
  }

  return x + text_width + left_padding + right_padding;
@@ -160,7 +160,7 @@ void render_vertical_item(struct menu_state
*state, cairo_t *cairo, const char *
  int left_padding) {

  int text_height;
- get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, str);
+ get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, "%s", str);
  int text_y = (state->line_height / 2.0) - (text_height / 2.0);

  if (background) {
@@ -172,7 +172,7 @@ void render_vertical_item(struct menu_state
*state, cairo_t *cairo, const char *

  cairo_move_to(cairo, x + left_padding, y + text_y);
  cairo_set_source_u32(cairo, foreground);
- pango_printf(cairo, state->font, 1, str);
+ pango_printf(cairo, state->font, 1, "%s", str);
 }

 void scroll_matches(struct menu_state *state) {
diff --git a/pango.c b/pango.c
index ac5ff4e..22c1487 100644
--- a/pango.c
+++ b/pango.c
@@ -66,7 +66,7 @@ void get_text_size(cairo_t *cairo, const char *font,
int *width, int *height,

 int text_width(cairo_t *cairo, const char *font, const char *text) {
  int text_width;
- get_text_size(cairo, font, &text_width, NULL, NULL, 1, text);
+ get_text_size(cairo, font, &text_width, NULL, NULL, 1, "%s", text);
  return text_width;
 }

-- 
2.40.1
Details
Message ID
<CSSZ3EX79E4R.W5NKZE9GOBHT@framework>
In-Reply-To
<CAKA5H008HZhT2rVSV1RV9Y41nWLZ+Hvu7Vyn6ocq-mc5rfUhcQ@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Hi, thanks for the patch! It looks like some of the lines got wrapped by
mistake? Could you fix and resend it?
Details
Message ID
<CSYZDPHRGFJY.2HCWS5PXX2F05@laptop>
In-Reply-To
<CSSZ3EX79E4R.W5NKZE9GOBHT@framework> (view parent)
DKIM signature
pass
Download raw message
Patch: +6 -6
I've sent the response a few days ago but I think it was a wrong addres.
Here is properly formatted patch.

---
 main.c  | 10 +++++-----
 pango.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c
index 496521f..f651fe6 100644
--- a/main.c
+++ b/main.c
@@ -110,7 +110,7 @@ int render_text(struct menu_state *state, cairo_t *cairo, const char *str,
		int left_padding, int right_padding) {

	int text_width, text_height;
	get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
	get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, "%s", str);
	int text_y = (state->line_height / 2.0) - (text_height / 2.0);

	if (background) {
@@ -133,7 +133,7 @@ int render_horizontal_item(struct menu_state *state, cairo_t *cairo, const char
		int left_padding, int right_padding) {

	int text_width, text_height;
	get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
	get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, "%s", str);
	int text_y = (state->line_height / 2.0) - (text_height / 2.0);

	if (x + left_padding + text_width > width) {
@@ -148,7 +148,7 @@ int render_horizontal_item(struct menu_state *state, cairo_t *cairo, const char

		cairo_move_to(cairo, x + left_padding, y + text_y);
		cairo_set_source_u32(cairo, foreground);
		pango_printf(cairo, state->font, 1, str);
		pango_printf(cairo, state->font, 1, "%s", str);
	}

	return x + text_width + left_padding + right_padding;
@@ -160,7 +160,7 @@ void render_vertical_item(struct menu_state *state, cairo_t *cairo, const char *
		int left_padding) {

	int text_height;
	get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, str);
	get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, "%s", str);
	int text_y = (state->line_height / 2.0) - (text_height / 2.0);

	if (background) {
@@ -172,7 +172,7 @@ void render_vertical_item(struct menu_state *state, cairo_t *cairo, const char *

	cairo_move_to(cairo, x + left_padding, y + text_y);
	cairo_set_source_u32(cairo, foreground);
	pango_printf(cairo, state->font, 1, str);
	pango_printf(cairo, state->font, 1, "%s", str);
}

void scroll_matches(struct menu_state *state) {
diff --git a/pango.c b/pango.c
index ac5ff4e..22c1487 100644
--- a/pango.c
+++ b/pango.c
@@ -66,7 +66,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,

int text_width(cairo_t *cairo, const char *font, const char *text) {
	int text_width;
	get_text_size(cairo, font, &text_width, NULL, NULL, 1, text);
	get_text_size(cairo, font, &text_width, NULL, NULL, 1, "%s", text);
	return text_width;
}

--
2.40.1
Details
Message ID
<CSZJOB9LW3UE.2P6ZOAW421N84@framework>
In-Reply-To
<CSYZDPHRGFJY.2HCWS5PXX2F05@laptop> (view parent)
DKIM signature
pass
Download raw message
There is one more instance of pango_printf in render_text which needs to
be fixed. Could you fix it and send a new patch?

Also, patches can be sent with git send-email to avoid formatting
issues. That method is preferred for sending patches to this list. See
https://git-send-email.io for a helpful guide to using git send-email.

On Mon May 29, 2023 at 2:46 PM EDT, Nikita Ivanov wrote:
> I've sent the response a few days ago but I think it was a wrong addres.
> Here is properly formatted patch.

These sentences above the --- become part of the commit message. If you
want to leave a note like this which should not be part of the commit
message, you should write them below the ---.

>
> ---
>  main.c  | 10 +++++-----
>  pango.c |  2 +-
>  2 files changed, 6 insertions(+), 6 deletions(-)
Reply to thread Export thread (mbox)