[PATCH 1/2] msgb: Add msgb_hexdump() function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Mon Mar 3 10:01:47 UTC 2014


Dear Holger

On 02.03.2014 08:06, Holger Hans Peter Freyther wrote:

> 
>> +			nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
>> +					  "%s[L%d]> ",
>> +					  osmo_hexdump(start, lxhs[i] - start),
>> +					  i+1);
> 
>> +	nchars = snprintf(buf + buf_offs, sizeof(buf) - buf_offs,
>> +			  "%s", osmo_hexdump(start, msg->tail - start));
>> +	nchars = snprintf(buf, sizeof(buf) - buf_offs,
>> +			  "!!! L%d out of range", i+1);
> 
> So sizeof(buf) - buf_offs can only be 0 when the output is already null
> terminated?

No, the expressions can never be 0 due to
  if (nchars < 0 || nchars + buf_offs >= sizeof(buf)) return "ERROR";

But even if it could, the string has already been \0 terminated by prior
calls to snprintf (the initial size value is always > 0).

Jacob




> 
> kind regards
> 	holger
> 





More information about the OpenBSC mailing list