adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile

Fri, 16 Dec 2016 23:22:18 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 16 Dec 2016 23:22:18 +0100
changeset 230
4044131874f9
parent 229
9db71925eaa8
child 231
35490eb48214

adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile

Makefile file | annotate | diff | comparison | revisions
test/buffer_tests.c file | annotate | diff | comparison | revisions
--- a/Makefile	Fri Nov 18 15:33:58 2016 +0100
+++ b/Makefile	Fri Dec 16 23:22:18 2016 +0100
@@ -63,21 +63,21 @@
 	
 debug: ucx-debug test-debug
 
-install: ucx $(PREFIX)/lib $(PREFIX)/include/ucx
-	cp ./build/release/libucx$(LIB_EXT) $(PREFIX)/lib && \
-	cp ./build/release/libucx$(SO_EXT) $(PREFIX)/lib && \
-        cp ./ucx/*.h $(PREFIX)/include/ucx
+install: ucx $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include/ucx
+	cp ./build/release/libucx$(LIB_EXT) $(DESTDIR)$(PREFIX)/lib && \
+	cp ./build/release/libucx$(SO_EXT) $(DESTDIR)$(PREFIX)/lib && \
+        cp ./ucx/*.h $(DESTDIR)$(PREFIX)/include/ucx
 
 uninstall:
-	$(RM) $(RMFLAGS) $(PREFIX)/include/ucx &&\
-	$(RM) $(RMFLAGS) $(PREFIX)/lib/libucx$(LIB_EXT) &&\
-	$(RM) $(RMFLAGS) $(PREFIX)/lib/libucx$(SO_EXT)
+	$(RM) $(RMFLAGS) $(DESTDIR)$(PREFIX)/include/ucx &&\
+	$(RM) $(RMFLAGS) $(DESTDIR)$(PREFIX)/lib/libucx$(LIB_EXT) &&\
+	$(RM) $(RMFLAGS) $(DESTDIR)$(PREFIX)/lib/libucx$(SO_EXT)
 
-$(PREFIX)/lib:
-	mkdir -p $(PREFIX)/lib
+$(DESTDIR)$(PREFIX)/lib:
+	mkdir -p $@
 
-$(PREFIX)/include/ucx:
-	mkdir -p $(PREFIX)/include/ucx
+$(DESTDIR)$(PREFIX)/include/ucx:
+	mkdir -p $@
 
 clean: FORCE
 	$(RM) $(RMFLAGS) build
--- a/test/buffer_tests.c	Fri Nov 18 15:33:58 2016 +0100
+++ b/test/buffer_tests.c	Fri Dec 16 23:22:18 2016 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "buffer_tests.h"
+#include <stdint.h>
 
 UCX_TEST(test_ucx_buffer_new) {
     UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND);
@@ -97,8 +98,12 @@
             "failed seek shall leave pos unchanged");
     
     b->pos = 0;
-    b->size = sizemax / 2 + 32;
-    off_t bigoff = sizemax / 2 - 16;
+    b->size = (sizemax >> 1) + 32;
+    
+    // we don't want to risk overflows in implicit constant casts
+    const size_t bigoff_comp = (sizemax >> 1) - 16;
+    off_t bigoff = (off_t)bigoff_comp;
+    
     r = ucx_buffer_seek(b, -bigoff, SEEK_CUR);
     UCX_TEST_ASSERT(r != 0, "seek cur underflow");
     UCX_TEST_ASSERT(b->pos == 0,

mercurial