⬢ DragonFlyBSD Kernel Audit
DF-4849 / fix.diff
← back to finding ↓ download raw
--- a/sys/tools/sound/snd_fxdiv_gen.awk	2026-06-29 12:51:19.000000000 +0000
+++ b/sys/tools/sound/snd_fxdiv_gen.awk	2026-09-24 13:19:45.287937155 +0000
@@ -55,11 +55,14 @@
 
 function calcdiv(r, x, y, z)
 {
-	y = floor(FXONE / x);
-	z = FXSHIFT;
-
-	while (shr((y * x), z) < 1)
-		y++;
+	y = 0;
+	for (z = FXSHIFT; z < 30; z++) {
+		y = floor((2 ^ z) / x);
+		while (y * x < (2 ^ z))
+			y++;
+		if ((y * x - (2 ^ z)) * FXONE < (2 ^ z))
+			break;
+	}
 
 	while ((y % 2) == 0 && z > 0) {
 		y = floor(y / 2);
@@ -123,9 +126,9 @@
 	printf("};\n\n");
 
 	printf("#define SND_FXDIV_MAX\t\t0x%08x\n", FXONE);
-	printf("#define SND_FXDIV(x, y)\t\t(((uint32_t)(x) *\t\t\t\\\n");
+	printf("#define SND_FXDIV(x, y)\t\t((uint32_t)(((uint64_t)(x) *\t\\\n");
 	printf("\t\t\t\t    snd_fxdiv_table[y][0]) >>\t\t\\\n");
-	printf("\t\t\t\t    snd_fxdiv_table[y][1])\n");
+	printf("\t\t\t\t    snd_fxdiv_table[y][1]))\n");
 	printf("#define SND_FXROUND(x, y)\t(SND_FXDIV(x, y) * (y))\n");
 	printf("#define SND_FXMOD(x, y)\t\t((x) - SND_FXROUND(x, y))\n\n");