git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/3] diff-parseopt: correct variable types that are used by parseopt

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 29, 2019, 09:11 UTC
Message-ID
<20190529091116.21898-2-pclouds@gmail.com>
In-Reply-To
<20190529091116.21898-1-pclouds@gmail.com>

Most number-related OPT_ macros store the value in an 'int' variable. Many of the variables in 'struct diff_options' have a different type, but during the conversion to using parse_options() I failed to notice and correct.

The problem was reported on s360x which is a big-endian architechture. The variable to store '-w' option in this case is xdl_opts, 'long' type, 8 bytes. But since parse_options() assumes 'int' (4 bytes), it will store bits in the wrong part of xdl_opts. The problem was found on little-endian platforms because parse_options() will accidentally store at the right part of xdl_opts.

There aren't much to say about the type change (except that 'int' for xdl_opts should still be big enough, since Windows' long is the same size as 'int' and nobody has complained so far). Some safety checks may be implemented in the future to prevent class of bugs.

Reported-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/diff.h b/diff.h
index b20cbcc091..d5e44baa96 100644
--- a/diff.h
+++ b/diff.h
@@ -169,7 +169,7 @@ struct diff_options {
 	const char *prefix;
 	int prefix_length;
 	const char *stat_sep;
-	long xdl_opts;
+	int xdl_opts;
 
 	/* see Documentation/diff-options.txt */
 	char **anchors;
-- 
2.22.0.rc0.322.g2b0371e29a
Previous: Nguyễn Thái Ngọc DuyNext: Eric Sunshine
Message 12 of 18 in “fix diff-parseopt regressions”
  1. 0/3 fix diff-parseopt regressionsNguyễn Thái Ngọc Duy, May 24, 2019
  2. 1/3 diff-parseopt: correct variable types that are used by parseoptNguyễn Thái Ngọc Duy, May 24, 2019
  3. Junio C HamanoMay 28, 2019
  4. 2/3 diff-parseopt: restore -U (no argument) behaviorNguyễn Thái Ngọc Duy, May 24, 2019
  5. 3/3 parse-options: check empty value in OPT_INTEGER and OPT_ABBREVNguyễn Thái Ngọc Duy, May 24, 2019
  6. 4/3 parse-options: make compiler check value type mismatchNguyễn Thái Ngọc Duy, May 24, 2019
  7. Todd ZullingerMay 24, 2019
  8. Todd ZullingerMay 24, 2019
  9. Duy NguyenMay 25, 2019
  10. Todd ZullingerMay 25, 2019
  11. 0/3 fix diff-parseopt regressionsNguyễn Thái Ngọc Duy, May 29, 2019
  12. 1/3 diff-parseopt: correct variable types that are used by parseoptNguyễn Thái Ngọc Duy, May 29, 2019
  13. Eric SunshineMay 29, 2019
  14. Todd ZullingerMay 29, 2019
  15. Junio C HamanoMay 29, 2019
  16. 2/3 diff-parseopt: restore -U (no argument) behaviorNguyễn Thái Ngọc Duy, May 29, 2019
  17. 3/3 parse-options: check empty value in OPT_INTEGER and OPT_ABBREVNguyễn Thái Ngọc Duy, May 29, 2019
  18. Junio C HamanoMay 29, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.