#define HASZERO(x) ~(((((x) & ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK)
gsize
-rspamd_strlcpy (gchar *dst, const gchar *src, gsize siz)
+rspamd_strlcpy_fast (gchar *dst, const gchar *src, gsize siz)
{
gchar *d = dst;
const gchar *s = src;
return (d - dst);
}
+size_t
+rspamd_strlcpy_safe (gchar *dst, const gchar *src, gsize siz)
+{
+ const gchar *osrc = src;
+ gchar *d = dst;
+ gsize nleft = siz;
+
+ if (nleft != 0) {
+ while (--nleft != 0) {
+ if ((*d++ = *src++) == '\0') {
+ break;
+ }
+ }
+ }
+
+ if (nleft == 0) {
+ if (siz != 0) {
+ *d = '\0';
+ }
+ }
+
+ return (d - dst);
+}
+
/*
* Try to convert string of length to long
*/
* @param siz length of destination buffer
* @return bytes copied
*/
-gsize rspamd_strlcpy (gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_fast (gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_safe (gchar *dst, const gchar *src, gsize siz);
+
+#if defined(__has_feature)
+# if __has_feature(address_sanitizer)
+# define rspamd_strlcpy rspamd_strlcpy_safe
+# else
+# define rspamd_strlcpy rspamd_strlcpy_fast
+# endif
+#else
+# define rspamd_strlcpy rspamd_strlcpy_fast
+#endif
/*
* Try to convert string of length to long