cras: Fix x86 build

crouton wants to build libcras for x86 (32-bit), so let's fix the
build.

In passing, fix 2 issues in dsp and server code, that crouton
does not really care about.

BUG=chromium:864815
TEST=x86-generic is fairly broken, so manual steps here:
   ./setup_board --board=x86-generic
   USE="-pam -readline -ncurses" emerge-x86-generic --nodeps -av \
       media-libs/speex media-libs/alsa-lib sys-apps/dbus sbc iniparser \
       libcap kmod acl util-linux readline udev ladspa-sdk
   USE=-cras-apm emerge-x86-generic --nodeps -av adhd

Change-Id: Ic1975ec3f503e7e484c79ab6b6d2ad05f57c3051
Reviewed-on: https://chromium-review.googlesource.com/1140341
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Louis Collard <louiscollard@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
diff --git a/cras/src/dsp/dsp_util.c b/cras/src/dsp/dsp_util.c
index fedd243..c95f0c5 100644
--- a/cras/src/dsp/dsp_util.c
+++ b/cras/src/dsp/dsp_util.c
@@ -3,6 +3,7 @@
  * found in the LICENSE file.
  */
 
+#include <limits.h>
 #include <syslog.h>
 
 #include "dsp_util.h"
@@ -508,7 +509,7 @@
 		for (j = 0; j < channels; j++, output++) {
 			float f = *(input_ptr[j]++) * 2147483648.0f;
 			f += (f >= 0) ? 0.5f : -0.5f;
-			*output = max(-2147483648, min(2147483647, (int)(f)));
+			*output = max((float)INT_MIN, min((float)INT_MAX, f));
 			*output >>= 8;
 		}
 }
@@ -527,7 +528,7 @@
 		for (j = 0; j < channels; j++, output += 3) {
 			float f = *(input_ptr[j]++) * 2147483648.0f;
 			f += (f >= 0) ? 0.5f : -0.5f;
-			tmp = max(-2147483648, min(2147483647, (int)(f)));
+			tmp = max((float)INT_MIN, min((float)INT_MAX, f));
 			tmp >>= 8;
 			memcpy(output, &tmp, 3);
 		}
@@ -546,7 +547,7 @@
 		for (j = 0; j < channels; j++, output++) {
 			float f = *(input_ptr[j]++) * 2147483648.0f;
 			f += (f >= 0) ? 0.5f : -0.5f;
-			*output = max(-2147483648, min(2147483647, (int)(f)));
+			*output = max((float)INT_MIN, min((float)INT_MAX, f));
 		}
 }
 
diff --git a/cras/src/server/cras_iodev.c b/cras/src/server/cras_iodev.c
index ed977c6..4caca3c 100644
--- a/cras/src/server/cras_iodev.c
+++ b/cras/src/server/cras_iodev.c
@@ -1057,7 +1057,8 @@
 
 	// Calculate whether the final output was non-empty, if requested.
 	if (is_non_empty) {
-		for (unsigned int i = 0; i < nframes * cras_get_format_bytes(fmt); i++) {
+		unsigned int i;
+		for (i = 0; i < nframes * cras_get_format_bytes(fmt); i++) {
 			if (frames[i]) {
 				*is_non_empty = 1;
 				break;
diff --git a/cras/src/tests/cras_test_client.c b/cras/src/tests/cras_test_client.c
index dd2a09d..7a1cb78 100644
--- a/cras/src/tests/cras_test_client.c
+++ b/cras/src/tests/cras_test_client.c
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <inttypes.h>
 #include <math.h>
 #include <pthread.h>
 #include <stdio.h>
@@ -674,7 +675,7 @@
 			return;
 		}
 
-		printf("Dumping AEC info to %s, stream %lu, fd %d\n",
+		printf("Dumping AEC info to %s, stream %" PRId64 ", fd %d\n",
 		       aecdump_file, stream_id, aecdump_fd);
 		cras_client_set_aec_dump(client, stream_id, 1, aecdump_fd);
 	} else {