code: plan9front

Download patch

ref: a15d6fcb8f44153e4a3054279935cb4b041373d1
parent: 0e2ae6f72708f8eb809762c18387edf289ac04a8
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Feb 15 10:52:24 EST 2024

ext4srv: fix a missed size decrement; fix 32-bit int crc32 on big endian

--- a/sys/src/cmd/ext4srv/ext4_crc32.c
+++ b/sys/src/cmd/ext4srv/ext4_crc32.c
@@ -136,8 +136,10 @@
 u32int ext4_crc32c(u32int crc, const void *buf, u32int size)
 {
 	const u8int *p = (const u8int *)buf;
-	while(size > 0 && ((uintptr)p & 3) != 0)
+	while(size > 0 && ((uintptr)p & 3) != 0){
+		size--;
 		crc = crc32c_tab[0][(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+	}
 
 	const u32int *p32 = (const u32int *)p;
 	while(size >= 4){
--- a/sys/src/cmd/ext4srv/include/ext4_crc32.h
+++ b/sys/src/cmd/ext4srv/include/ext4_crc32.h
@@ -19,6 +19,7 @@
  * @return	updated crc32c value*/
 u32int ext4_crc32c(u32int crc, const void *buf, u32int size);
 
+#ifndef CONFIG_BIG_ENDIAN
 #define ext4_crc32_u(crc, x) ( \
 	(crc) = (crc) ^ (x), \
 	crc32c_tab[0][(crc)>>24] ^ \
@@ -26,5 +27,14 @@
 	crc32c_tab[2][((crc)>>8) & 0xff] ^ \
 	crc32c_tab[3][(crc) & 0xff] \
 )
+#else
+#define ext4_crc32_u(crc, x) ( \
+	(crc) = (crc) ^ (x), \
+	crc32c_tab[0][(crc) & 0xff] ^ \
+	crc32c_tab[1][((crc)>>8) & 0xff] ^ \
+	crc32c_tab[2][((crc)>>16) & 0xff] ^ \
+	crc32c_tab[3][(crc)>>24] \
+)
+#endif
 
 void ext4_crc32_init(void);