summaryrefslogtreecommitdiff
path: root/sys-process/psinfo/files/psinfo-0.12-char.patch
blob: d2936163318562aff294907070de938e627ede7b (plain)
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
Subject: [PATCH] fix 'char' issue in RISC-V (also Arm64) platform

According to RISC-V psAbi manual[1], "char" is equivalent to "unsigned char",
so in RISC-V/ARM64 the following code will always print out 'false',
while in X86_64 it will print out 'true'

test() {
  char val = EOF;
  printf("%s", val == EOF ? "true" : "false");
}

According to man page, the following two function return value is 'int':
       int getopt(int argc, char *const argv[],
                  const char *optstring);
       int fgetc(FILE *stream);

so, we use 'int' variable and then convert to 'char' if nencessary

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
snip of description:
   C/C++ type representations
   char is unsigned.

Bug: https://bugs.gentoo.org/872821

Signed-off-by: Yixun Lan <dlan@gentoo.org>
---
 psinfo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/psinfo.c b/psinfo.c
index 90a6d8f..05acedf 100644
--- a/psinfo.c
+++ b/psinfo.c
@@ -172,14 +172,15 @@ int parse_proc_wchan(FILE * f, struct process_info *p)
 int parse_proc_arrayfile(char *name, char ***s)
 {
 	FILE *f;
-	int res = 1;
+	int ret, res = 1;
 
 	if ((f = fopen(name, "r")) != NULL) {
 		char *buf;
 		int len = 0, bufsize = 1024, count = 0;
 
 		buf = malloc(bufsize);
-		while ((buf[len++] = fgetc(f)) != EOF) {
+		while ((ret = fgetc(f)) != EOF) {
+			buf[len++] = ret & 0xFF;
 			if (buf[len - 1] == 0) {
 				*s = realloc(*s, (count + 2) * sizeof(char *));
 				(*s)[count] = malloc(len);
@@ -673,8 +674,7 @@ void print_help()
 int main(int argc, char **argv)
 {
 	struct process_info *p;
-	int pid, output_general = 0, output_cpu = 0, output_io = 0, output_memory = 0, output_privilege = 0, output_signal = 0, result = 0;
-	char c;
+	int c, pid, output_general = 0, output_cpu = 0, output_io = 0, output_memory = 0, output_privilege = 0, output_signal = 0, result = 0;
 
 	opterr = 0;
 	if (argc <= 1) {
-- 
2.37.3