Hello Tim,

On 09/10/2021 10:55 PM, Tim Düsterhus wrote:
If it's not a NULL pointer then it must be a valid pointer. I don't
quite understand why you would need to replace this by an empty constant
string then? Is this about a missing NUL terminator? Otherwise a valid
pointer with .len == 0 would be equivalent to "".


No, v.ptr is not a null pointer and points to the wrong location, v.len
is equal to 0.

For example I added to the source two calls to the printf () function,
one before the htx_get_blk_value() function call and the other after:

---------
printf(">>> n = { %p '%s' %zu }, v = { %p '%s' %zu }\n", n.ptr, n.ptr, n.len, v.ptr, v.ptr, v.len);

v = htx_get_blk_value(htx, blk);

printf(">>> v = { %p '%s' %zu }\n", v.ptr, v.ptr, v.len);
---------

I intentionally did not write the string format as '%.*s' so that the
contents can be seen.  These two headers are treated here:

1, 'ot-ctx-uberctx-haproxy_id: '
2. 'ot-ctx-uber-trace-id: 3c4069d777e89019:3c4069d777e89019:0:1'

, and this is the result:

1st header:
>>> n = { 0x56079098bec1 'ot-ctx-uberctx-haproxy_idot-ctx-uber-trace-id3c4069d777e89019:3c4069d777e89019:0:1' 25 }, v = { (nil) '(null)' 0 } >>> v = { 0x56079098beda 'ot-ctx-uber-trace-id3c4069d777e89019:3c4069d777e89019:0:1' 0 }

As can be seen from the example, v.ptr = 0x56079098beda, v.len = 0.

2nd header:
>>> n = { 0x56079098beda 'ot-ctx-uber-trace-id3c4069d777e89019:3c4069d777e89019:0:1' 20 }, v = { (nil) '(null)' 0 }
>>> v = { 0x56079098beee '3c4069d777e89019:3c4069d777e89019:0:1' 37 }

Maybe I use htx_get_blk_name()/htx_get_blk_value() in this function in
an inappropriate way, so I get such a result.

Unrelated to that: Having worked quite a bit with the ist API I would
generally recommend using the helper functions in ist.h (possibly adding
new ones if they are helpful) instead of directly touching the struct.
It makes refactoring much easier, because it's easy to find the function
calls vs. accessing struct members which might be available on different
structs.

As an example in flt_ot_http_headers_get you could use an ist for prefix
and then simply use isteqi() instead of strncasecmp().

The functions strncasecmp() and isteqi() are not compatible, because
isteqi() requires that the lengths of the strings being compared are
equal, whereas in this function that is not the case.  In addition, the
prefix and len should be put in the ist structure and n.len reduced to
the size of len, this is an unnecessary complication.


 > Of course, it could look like this:
 >
 > if (v.len == 0)
 > v.ptr = "" /* or v = ist("") */;
 >

In your example I would prefer v = ist("") over v.ptr = "" and leave the
heavy lifting up to the compiler for that reason.


Ok, I will use ist("").

Best regards,

--
Zaga    <[email protected]>

What can change the nature of a man?

Reply via email to