explicit html_component_opacity(std::string_view v)
: raw_value(v)
{
- char *endptr;
- auto val = std::strtof(v.data(), &endptr);
- if (endptr != v.data() && val >= 0.0f && val <= 1.0f) {
- numeric_value = val;
+ char numbuf[128], *endptr = nullptr;
+ numbuf[0] = '\0';
+ rspamd_strlcpy(numbuf, v.data(), MIN(v.size(), sizeof(numbuf)));
+ auto num = g_ascii_strtod(numbuf, &endptr);
+
+ if (!std::isnan(num)) {
+ numeric_value = num;
}
}
/*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
if (n-- != 0) {
if (((uintptr_t) s & MEM_ALIGN) == ((uintptr_t) d & MEM_ALIGN)) {
/* Init copy byte by byte */
- for (; ((uintptr_t) s & MEM_ALIGN) && n && (*d = *s); n--, s++, d++)
- ;
+ for (; ((uintptr_t) s & MEM_ALIGN) && n && (*d = *s); n--, s++, d++);
if (n && *s) {
wd = (void *) d;
ws = (const void *) s;
}
/* Copy the rest */
- for (; n && (*d = *s); n--, s++, d++)
- ;
+ for (; n && (*d = *s); n--, s++, d++);
*d = 0;
}
const glong cutoff = G_MAXLONG / 10, cutlim = G_MAXLONG % 10;
gboolean neg;
+ /* Avoid absurd length */
+ if (len == 0 || len > sizeof("-18446744073709551615")) {
+ return FALSE;
+ }
+
/* Case negative values */
if (*p == '-') {
neg = TRUE;
gulong v = 0;
const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10;
+ if (len == 0 || len > sizeof("-18446744073709551615")) {
+ return FALSE;
+ }
/* Some preparations for range errors */
CONV_STR_LIM_DECIMAL(G_MAXULONG);
const char *p = s, *end = s + len;
if (!e[1]) {
- for (; p < end && *p != *e; p++)
- ;
+ for (; p < end && *p != *e; p++);
return p - s;
}
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
- ;
- for (; p < end && !BITOP(byteset, *(unsigned char *) p, &); p++)
- ;
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++);
+ for (; p < end && !BITOP(byteset, *(unsigned char *) p, &); p++);
return p - s;
}
const char *p = s, *end = s + len;
if (!e[1]) {
- for (; p < end && *p == *e; p++)
- ;
+ for (; p < end && *p == *e; p++);
return p - s;
}
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
- ;
- for (; p < end && BITOP(byteset, *(unsigned char *) p, &); p++)
- ;
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++);
+ for (; p < end && BITOP(byteset, *(unsigned char *) p, &); p++);
return p - s;
}