diff mbox series

tools: fdtgrep: Use unsigned chars for arrays

Message ID 20210210194309.07d1dec7@DUFFMAN
State Accepted
Commit ac549ac82d1b09fa9b912f64784426dec9052c20
Delegated to: Simon Glass
Headers show
Series tools: fdtgrep: Use unsigned chars for arrays | expand

Commit Message

Samuel Dionne-Riel Feb. 11, 2021, 12:43 a.m. UTC
Otherwise, values over 127 end up prefixed with ffffff.

Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Cc: Simon Glass <sjg@chromium.org>
---

Minimal reproduction:

```
// repro.dts
/dts-v1/;

/ {
    ra = [ 7f ];
    rb = [ 80 ];
};
```

Steps used to compile:

 $ dtc repro.dts > repro.dtb

Without the fix:

 $ fdtgrep --include-node / repro.dtb
/ {
    ra = [7f];
    rb = [ffffff80];
};

With the fix:

 $ fdtgrep --include-node / repro.dtb
/ {
    ra = [7f];
    rb = [80];
};

---

 tools/fdtgrep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Feb. 13, 2021, 4:17 a.m. UTC | #1
On Wed, 10 Feb 2021 at 17:43, Samuel Dionne-Riel <samuel@dionne-riel.com> wrote:
>
> Otherwise, values over 127 end up prefixed with ffffff.
>
> Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>
> Minimal reproduction:
>
> ```
> // repro.dts
> /dts-v1/;
>
> / {
>     ra = [ 7f ];
>     rb = [ 80 ];
> };
> ```
>
> Steps used to compile:
>
>  $ dtc repro.dts > repro.dtb
>
> Without the fix:
>
>  $ fdtgrep --include-node / repro.dtb
> / {
>     ra = [7f];
>     rb = [ffffff80];
> };
>
> With the fix:
>
>  $ fdtgrep --include-node / repro.dtb
> / {
>     ra = [7f];
>     rb = [80];
> };
>
> ---
>
>  tools/fdtgrep.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass March 16, 2021, 5:58 a.m. UTC | #2
On Wed, 10 Feb 2021 at 17:43, Samuel Dionne-Riel <samuel@dionne-riel.com> wrote:
>
> Otherwise, values over 127 end up prefixed with ffffff.
>
> Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>
> Minimal reproduction:
>
> ```
> // repro.dts
> /dts-v1/;
>
> / {
>     ra = [ 7f ];
>     rb = [ 80 ];
> };
> ```
>
> Steps used to compile:
>
>  $ dtc repro.dts > repro.dtb
>
> Without the fix:
>
>  $ fdtgrep --include-node / repro.dtb
> / {
>     ra = [7f];
>     rb = [ffffff80];
> };
>
> With the fix:
>
>  $ fdtgrep --include-node / repro.dtb
> / {
>     ra = [7f];
>     rb = [80];
> };
>
> ---
>
>  tools/fdtgrep.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
index e4112b8f69..db512465db 100644
--- a/tools/fdtgrep.c
+++ b/tools/fdtgrep.c
@@ -213,7 +213,7 @@  static void utilfdt_print_data(const char *data, int len)
 	} else {
 		printf(" = [");
 		for (i = 0; i < len; i++)
-			printf("%02x%s", *p++, i < len - 1 ? " " : "");
+			printf("%02x%s", (unsigned char)*p++, i < len - 1 ? " " : "");
 		printf("]");
 	}
 }