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

[PATCH 32/32] date.c: fix code that may overflow 'int' before it is converted to 'time_t'

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Nov 4, 2019, 09:59 UTC
Message-ID
<20191104095923.116086-3-gitter.spiros@gmail.com>
In-Reply-To
<20191104095923.116086-1-gitter.spiros@gmail.com>

Fix the LGTM warning fired by the rule that finds code that could convert the result of an integer multiplication to a larger type. Since the conversion applies after the multiplication, arithmetic overflow may still occur.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 date.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/date.c b/date.c
index 041db7db4e..b8dcbdbb0e 100644
--- a/date.c
+++ b/date.c
@@ -1172,7 +1172,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
 	while (tl->type) {
 		int len = strlen(tl->type);
 		if (match_string(date, tl->type) >= len-1) {
-			update_tm(tm, now, tl->length * *num);
+			update_tm(tm, now, (time_t)tl->length * *num);
 			*num = 0;
 			*touched = 1;
 			return end;
-- 
2.24.0.rc0.467.g566ccdd3e4.dirty
Previous: Johannes SchindelinNext: SZEDER Gábor
Message 9 of 15 in “ident.c: fix LGTM warning on the possible abuse of the '=' operator”
  1. 30/32 ident.c: fix LGTM warning on the possible abuse of the '=' operatorElia Pinto, Nov 4, 2019
  2. 31/32 commit-graph.c: fix code that could convert the result of an integer multiplication to a larger typeElia Pinto, Nov 4, 2019
  3. Junio C HamanoNov 6, 2019
  4. Danh DoanNov 7, 2019
  5. Junio C HamanoNov 7, 2019
  6. Danh DoanNov 7, 2019
  7. Johannes SchindelinNov 7, 2019
  8. Johannes SchindelinNov 7, 2019
  9. 32/32 date.c: fix code that may overflow 'int' before it is converted to 'time_t'Elia Pinto, Nov 4, 2019
  10. SZEDER GáborNov 4, 2019
  11. Elia PintoNov 4, 2019
  12. Phillip WoodNov 4, 2019
  13. Elia PintoNov 4, 2019
  14. Junio C HamanoNov 6, 2019
  15. Johannes SchindelinNov 6, 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.