File: fix-type-warnings.patch

package info (click to toggle)
a56 1.3%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 664 kB
  • sloc: yacc: 7,550; ansic: 5,851; makefile: 231; awk: 4; sh: 1
file content (102 lines) | stat: -rw-r--r-- 3,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From: Ben Hutchings <benh@debian.org>
Date: Fri, 26 Jul 2024 23:32:47 +0200
Subject: Fix type warnings
Forwarded: not-needed as there is no upstream anymore

gcc warns:

keybld.c: In function ‘follow’:
keybld.c:119:50: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  119 |                         arcp->arg = arcup->arg = (void *)n_user_actions;
      |
keybld.c:185:47: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  185 |                                 printf("%d", -(int)tp->arg - 1);
      |

The trans::arg struct member is declared with type void * but is used
to store both pointers and integers.  This is generally unsafe, but it
is OK to store pointers in intptr_t-typed variables.  Change
trans::arg to intptr_t and update the casts accordingly.

keybld.c: In function ‘dump_machine’:
keybld.c:171:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
  171 |         printf("/* %d bytes required for transition table storage */\n",
      |                    ~^
      |                     |
      |                     int
      |                    %ld
  172 |                 sizeof(short) * TRANSITIONS * n_states);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             |
      |                                             long unsigned int

Fix this by changing the format string to "%zu".

kparse.c: In function ‘kparse’:
kparse.c:2480:55: warning: array subscript has type ‘char’ [-Wchar-subscripts]
 2480 |                 short transition = transitions[state][*kp];
      |                                                       ^~~

This warning is implemented because the char type may or may not be
signed.  In this case we know char is ASCII alphanumeric so that
doesn't actually make a difference.  Add a cast to unsigned char to
avoid the warning.

---
--- a/keybld.c
+++ b/keybld.c
@@ -10,6 +10,7 @@
  * provided "as is" without express or implied warranty.
  *
  */
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -22,7 +23,7 @@ struct state {
 	char *seen;
 	struct trans {
 		char action;
-		void *arg;
+		intptr_t arg;
 	} trans[TRANSITIONS];
 	struct state *next;
 } empty_state, *stop = NULL, *scur = NULL;
@@ -122,16 +123,16 @@ int follow(char c, char *tp, struct stat
 			return -1;
 		} else {
 			arcp->action = arcup->action = TERMINAL;
-			arcp->arg = arcup->arg = (void *)n_user_actions;
+			arcp->arg = arcup->arg = n_user_actions;
 			return 0;
 		}
 	} else {
 		if(arcp->action == GOTO) {
-			return follow(*tp, tp + 1, arcp->arg);
+			return follow(*tp, tp + 1, (struct state *)arcp->arg);
 		} else {
 			struct state *new = new_state(tp);
 			arcp->action = arcup->action = GOTO;
-			arcp->arg = arcup->arg = (void *)new;
+			arcp->arg = arcup->arg = (intptr_t)new;
 			return follow(*tp, tp + 1, new);
 		}
 	}
@@ -174,7 +175,7 @@ void dump_machine(void)
 
 	printf("/* state machine generated by keybld */\n");
 	printf("/* states=%d actions=%d */\n", n_states, n_user_actions);
-	printf("/* %d bytes required for transition table storage */\n",
+	printf("/* %zu bytes required for transition table storage */\n",
 		sizeof(short) * TRANSITIONS * n_states);
 
 	printf("short transitions[%d][%d] = {\n", n_states, TRANSITIONS);
@@ -208,7 +209,7 @@ int kparse(char *kp)\n\
 	int state = 0;\n\
 \n\
 	for(;;) {\n\
-		short transition = transitions[state][*kp];\n");
+		short transition = transitions[state][(unsigned char)*kp];\n");
 
 printf("\
 		if(transition == 0) {\n\