[OpenSIPS-Devel] Possible bug in dbt_lib.c with suggested correction

Bogdan-Andrei Iancu bogdan at voice-system.ro
Thu Jan 21 18:56:51 CET 2010


Hi Michael,

There is a huge difference between STR and STRING . STR is a string with 
length (a start pointer and its len), while STRING is just a starting 
pointer with a \0 terminator at the end.

STR and BLOB are compatible as they do not rely on the \0 terminator , 
but STRING and BLOB are not alike as BLOB contain data (including \0).

Regards,
Bogdan

Michael Schloh von Bennewitz wrote:
> Hello Bogdan,
>
> On Tues., Jan 20, 2010, Bogdan-Andrei Iancu wrote:
>   
>> Michael Schloh von Bennewitz wrote:
>>     
>>> Hello list,
>>>
>>> It would seem that Bogdan's recent correction relating to the BLOB
>>> datatype support was not complete.
>>>
>>> Index: modules/db_text/dbt_lib.c
>>> diff -Nau modules/db_text/dbt_lib.c.orig modules/db_text/dbt_lib.c
>>> --- modules/db_text/dbt_lib.c.orig	2010-01-20 11:10:07.967990871 +0100
>>> +++ modules/db_text/dbt_lib.c	2010-01-20 11:10:21.649138475 +0100
>>> @@ -440,7 +440,7 @@
>>>  		case DB_DOUBLE:
>>>  			break;
>>>  		case DB_STRING:
>>> -			if(_t0==DB_STR)
>>> +			if(_t0==DB_STR || _t0==DB_BLOB)
>>>  				return 0;
>>>  		case DB_STR:
>>>  			if(_t0==DB_STRING || _t0==DB_BLOB)
>>>
>>>
>>> The '-' and '+' indicate my suggested correction, keeping in line
>>> with Bogdan's recent change SVN revision 6382.
>>>
>>>       
>> Have this fix resulted from troubleshooting some error ? or it is a
>> logical fix ?
>>
>>     
> Your own comment for checkin 6382 is 'fixed incomatibility between
> BLOB data type and string format for columns' and your change is:
>
> --- trunk/modules/db_text/dbt_lib.c	2009/07/21 07:45:05	5901
> +++ trunk/modules/db_text/dbt_lib.c	2009/12/09 16:33:12	6382
> @@ -446,7 +446,7 @@
>  			if(_t0==DB_STRING || _t0==DB_BLOB)
>  				return 0;
>  		case DB_BLOB:
> -			if(_t0==DB_STR)
> +			if(_t0==DB_STR || _t0==DB_STRING)
>  				return 0;
>  		case DB_BITMAP:
>  			if (_t0==DB_INT)
>
> That fixed a nondocumented bug in which the sip_trace module could
> not write to its table when the database is dbtext.
>
> Then I looked at the code block and saw that DB_STR and DB_STRING
> are logically equal. See 'case DB_STRING: if(_t0==DB_STR) return 0;'
> above.
>
> ...so I assume that if comparing DB_STR and DB_BLOB should return
> 0, then comparing DB_STRING and DB_BLOB should return 0 as well.
> It's a long winded way of saying 'my suggestion is a logical fix.'
> I've found no runtime failure to motivate this correction, although
> there could be one hiding.
>
>   
>> Because the STRING and BLOB times are not really compatible. STRING
>> is zero terminated data while BLOB contains data (including 0), if
>> you get my point.
>>
>>     
> Just how different are DB_STRING and DB_STR? Is one zero terminated
> and the other not? If that's right, then maybe the best thing is to
> return 0 when comparing DB_BLOB with whichever [DB_STR|DB_STRING] is
> most similar (in which zero termination plays a role in deciding.)
>
> ...and if that's how the code was in the first place, then just
> disregard my patch suggestion.
>
> Regards,
> Michael
>
>   


-- 
Bogdan-Andrei Iancu
www.voice-system.ro




More information about the Devel mailing list