Hi I hope this looks better this time.

Kindest regards.

On 29 February 2016 at 11:49, David CARLIER <[email protected]> wrote:

> Sorry I did not see the whole email, just realized ok why not :-)
>
> On 29 February 2016 at 11:18, Willy Tarreau <[email protected]> wrote:
>
>> On Mon, Feb 29, 2016 at 10:37:33AM +0000, David CARLIER wrote:
>> > Hi no problems it is not a bugfix at all, usually just better to copy a
>> > const char instead of casting it in this sort of situation. Nothing
>> else.
>>
>> Yes clearly, but as I said it's better to fix it anyway. Are you
>> interested
>> in working on the solution I proposed ?
>>
>> Thanks,
>> Willy
>>
>>
>
From 1c42759fbd31a18c6d3efe669c316a53c4ad6251 Mon Sep 17 00:00:00 2001
From: David Carlier <[email protected]>
Date: Mon, 29 Feb 2016 19:51:17 +0000
Subject: [PATCH] CLEANUP: log

Different approach to silent cast qualifier warning.
Creating 'new' inline function variant of the chunk_initlen
but marked the underlying string as read only instead.
---
 include/common/chunk.h | 14 ++++++++++++++
 src/log.c              |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/common/chunk.h b/include/common/chunk.h
index b74c767..4e2d094 100644
--- a/include/common/chunk.h
+++ b/include/common/chunk.h
@@ -77,6 +77,20 @@ static inline int chunk_initlen(struct chunk *chk, char *str, size_t size, int l
 	return 1;
 }
 
+/* same as above but the chunk is marked as immutable. */
+static inline int chunk_initlen_const(struct chunk *chk, const char *str, int len)
+{
+
+	if (len < 0)
+		return 0;
+
+	chk->str  = (char *)str;
+	chk->len  = len;
+	chk->size = 0;
+
+	return 1;
+}
+
 /* this is only for temporary manipulation, the chunk is read-only */
 static inline void chunk_initstr(struct chunk *chk, const char *str)
 {
diff --git a/src/log.c b/src/log.c
index 3e25bc7..6b71ef3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -833,7 +833,7 @@ char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct lo
 			struct chunk chunk;
 			char *ret;
 
-			chunk_initlen(&chunk, (char *)src, 0, len);
+			chunk_initlen_const(&chunk, src, len);
 			ret = escape_chunk(dst, dst + size, '\\', rfc5424_escape_map, &chunk);
 			if (ret == NULL || *ret != '\0')
 				return NULL;
-- 
2.7.0

Reply via email to