On Tue, Jul 7, 2020 at 7:09 PM <[email protected]> wrote:
>
> Antonio:
> ...
> > with my gcc 10.1.0 seams enough to change
> > - the types of "i" and "j" in the function and
> > - of "length" in the function prototype
> > all to "unsigned int".
> > It seems a good compromise to avoid cast and keep code readability.
> > Would you check if it works on your side too?
>
> Consider this test program:
>
> $ cat xx.c
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[]) {
>   char line[81];
>   unsigned int i;
>   int ix;
>
>   for (ix = 1; ix < argc; ix++) {
>     errno = 0;
>     i = strtoul(argv[ix], NULL, 0);
>     if (errno) continue;
>     snprintf(line, 5, "%04x", i);
>     printf("%s\n", line);
>   }
>
>   return 0;
> }
> $ cc xx.c -o xx
> $ ./xx 0x4532 0x4533 0x1234532  0x1234533
> 4532
> 4533
> 1234
> 1234

You are right, snprintf(,5 ,...) takes the first 5 chars (actually 4 + '\0').


> $
>
> Just because the compiler doesn't complain, does not mean that it
> is correct. The correct action would be to either print the full
> unsigned range or restrict the range to what is printable with "%04x",
> i.e. a 16 bit value.

You are considering the case of length exceeding 4 hex char, which is
in general possible.
In this case, I would prefer breaking the format instead of printing
only the lower 16 bits.
By changing snprintf(, 5,...) to snprintf(, 9,...) we would get, at
the 16 bit boundary:
fff0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
10000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

The buffer line[81] is already overdimensioned, since 4+16*3 + 1 = 53!

>
> > Could you propose a patch in gerrit for further check?
>
> Found http://openocd.zylin.com/#/q/status:open but don't know what to
> do to when I press the register thing, there seems not to be any field
> to register with. The HACKING file doesn't help either.

I think you cannot use anymore a pair username/password in openocd gerrit.
You need to have an account in gmail, or github, or others, and use it to login.

Antonio

>
> Regards,
> /Karl Hammar
>
>
>
>
> _______________________________________________
> OpenOCD-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openocd-devel


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to