This is the common mistake! Unsigned types was added for another reason to 
standart. But than their sense was perverted and many programmers start use 
them for values that cant be negative. But C standart has integer promoution — 
all arifmetics usually done in int. Just try to change it back to unsigned (in 
this function) and you will need several type casts.
 
 
--
Alexander Gabitov
 
  
>Пятница, 5 марта 2021, 13:27 +03:00 от Antonio Borneo 
><borneo.anto...@gmail.com>:
> 
> 
>On Fri, Mar 5, 2021, 08:08 Alexander Gabitov via OpenOCD-devel < 
>openocd-devel@lists.sourceforge.net > wrote:
>>The better way — is to fix jlink_clock_data interface. Unsigned type was a 
>>bad choice. Historically it was added to standart for unsigned arithmetics 
>>only(for rolling over max value to zero).
>> 
>>static void jlink_clock_data(const uint8_t *out, int out_offset,
>>                 const uint8_t *tms_out, int tms_offset,
>>                 uint8_t *in, int in_offset,
>>                 int length)
> 
>Alexander,
> 
>both in_offset and length carry unsigned values only; for me they should 
>remain unsigned and the mathematics should be modified to not use negative 
>values
> 
>Regards
>Antonio
> 
> 
> 
>>{
>>    do {
>>        int available_length = (JLINK_TAP_BUFFER_SIZE * 8) - tap_length;
>>        if (available_length < length ||
>>            (in && pending_scan_results_length == MAX_PENDING_SCAN_RESULTS)) {
>>            if (jlink_flush() != ERROR_OK)
>>                return;
>>            available_length = JLINK_TAP_BUFFER_SIZE * 8;
>>        }
>>        struct pending_scan_result *pending_scan_result =
>>            &pending_scan_results_buffer[pending_scan_results_length];
>>        int scan_length = length > available_length ? available_length : 
>>length;         ….
>>}
>> 
>> 
>>--
>>Alexander Gabitov
>> 
>>  
>>>Пятница, 5 марта 2021, 8:12 +03:00 от Alexander Gabitov via OpenOCD-devel < 
>>>openocd-devel@lists.sourceforge.net >:
>>> 
>>>I’m working on API.
>>> 
>>>By the way. I think there is a bug(jlink.c:2032):
>>>        unsigned available_length = JLINK_TAP_BUFFER_SIZE - tap_length / 8;
>>>        if (!available_length ||
>>>            (in && pending_scan_results_length == MAX_PENDING_SCAN_RESULTS)) 
>>>{
>>>            if (jlink_flush() != ERROR_OK)
>>>                return;
>>>            available_length = JLINK_TAP_BUFFER_SIZE;
>>>        }
>>>        struct pending_scan_result *pending_scan_result =
>>>            &pending_scan_results_buffer[pending_scan_results_length];
>>>        unsigned scan_length =  length > available_length ?
>>>            available_length : length;
>>> 
>>>Here length is amount of bits, but  available_length  is amount of bytes! So 
>>>this expression seems to be wrong.
>>> 
>>>Also during debug i found that first condition becomes true only when second 
>>>clause is true —  pending_scan_results_length == MAX_PENDING_SCAN_RESULTS.
>>>And more over condition "!available_length" — looks very strange due to 
>>>formula which calculates it.
>>> 
>>>I would correct it all like that:
>>>        int available_length = (JLINK_TAP_BUFFER_SIZE * 8) - tap_length;
>>>        if (available_length < length ||
>>>            (in && pending_scan_results_length == MAX_PENDING_SCAN_RESULTS)) 
>>>{
>>>            if (jlink_flush() != ERROR_OK)
>>>                return;
>>>            available_length = JLINK_TAP_BUFFER_SIZE * 8;
>>>        }
>>>        struct pending_scan_result *pending_scan_result =
>>>            &pending_scan_results_buffer[pending_scan_results_length];
>>>        unsigned scan_length = length > available_length ?
>>>            available_length : length;
>>> 
>>>--
>>>Alexander Gabitov
>>> 
>>> 
>>>_______________________________________________
>>>OpenOCD-devel mailing list
>>>OpenOCD-devel@lists.sourceforge.net
>>>https://lists.sourceforge.net/lists/listinfo/openocd-devel
>>  _______________________________________________
>>OpenOCD-devel mailing list
>>OpenOCD-devel@lists.sourceforge.net
>>https://lists.sourceforge.net/lists/listinfo/openocd-devel
 
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to