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

comm: fix appending doubles to events #244

Merged
merged 2 commits into from Apr 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/comm.c
Expand Up @@ -7,27 +7,22 @@

#include <string.h>

/* =========================== PUBLIC API =========================== */

static GString *
append_escaped (GString *dest, const gchar *src);

/* =========================== PUBLIC API =========================== */

void
uzbl_comm_string_append_double (GString *buf, double val)
{
gsize pos = buf->len;

/* Make sure the formatted double fits in the buffer. */
if (buf->allocated_len - pos < G_ASCII_DTOSTR_BUF_SIZE) {
g_string_set_size (buf, pos + G_ASCII_DTOSTR_BUF_SIZE);
}
gchar double_buf[G_ASCII_DTOSTR_BUF_SIZE];

/* Format in C locale. */
char *tmp = g_ascii_formatd (
buf->str + pos,
buf->allocated_len - pos,
g_ascii_formatd (
double_buf,
sizeof (double_buf),
"%.2g", val);
buf->len += pos + strlen (tmp);
g_string_append (buf, double_buf);
}

GString *
Expand Down