Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"%" symbol does really weird things... #36

Open
AnotherRandomGitHubAccount opened this issue Sep 21, 2023 · 1 comment
Open

"%" symbol does really weird things... #36

AnotherRandomGitHubAccount opened this issue Sep 21, 2023 · 1 comment

Comments

@AnotherRandomGitHubAccount

When typing %, it usually doesn't appear, and depending on what you type next, weird things happen. for example if you press %b, it will make a long string of 1's and 0's. not sure if this is intentional and i just don't understand it, but i think that it should be fixed, but if there is a reason its there, it should be placed in the man page or in README.md

@IIIlllIIIllI
Copy link

thats caused by vsnprintf it interprets % as the start of a format specifier
%b makes weird things happen (vsnprintf tries to interpret this as some format)
removing it fixes this:

diff --git a/draw.c b/draw.c
index f90570e..d082e25 100644
--- a/draw.c
+++ b/draw.c
@@ -110,13 +110,8 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
 void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
 		int *baseline, double scale, bool markup, const char *fmt, ...) {
 	char buf[max_chars];
-
-	va_list args;
-	va_start(args, fmt);
-	if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) {
-		strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
-	}
-	va_end(args);
+	strncpy(buf, fmt, max_chars -1);
+	buf[max_chars -1] = '\0';
 
 	PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
 	pango_cairo_update_layout(cairo, layout);
@@ -129,16 +124,8 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
 
 void pango_printf(cairo_t *cairo, const char *font,
 		double scale, bool markup, const char *fmt, ...) {
-	char buf[max_chars];
 
-	va_list args;
-	va_start(args, fmt);
-	if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) {
-		strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
-	}
-	va_end(args);
-
-	PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
+	PangoLayout *layout = get_pango_layout(cairo, font, fmt, scale, markup);
 	cairo_font_options_t *fo = cairo_font_options_create();
 	cairo_get_font_options(cairo, fo);
 	pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants