Merge "Replace uses of sprintf(3) with snprintf(3)."
diff --git a/libc/bionic/semaphore.cpp b/libc/bionic/semaphore.cpp
index c23eb75..dabfea0 100644
--- a/libc/bionic/semaphore.cpp
+++ b/libc/bionic/semaphore.cpp
@@ -86,11 +86,6 @@
int sem_init(sem_t* sem, int pshared, unsigned int value) {
- if (sem == NULL) {
- errno = EINVAL;
- return -1;
- }
-
// Ensure that 'value' can be stored in the semaphore.
if (value > SEM_VALUE_MAX) {
errno = EINVAL;
@@ -104,11 +99,7 @@
return 0;
}
-int sem_destroy(sem_t* sem) {
- if (sem == NULL) {
- errno = EINVAL;
- return -1;
- }
+int sem_destroy(sem_t*) {
return 0;
}
@@ -205,11 +196,6 @@
}
int sem_wait(sem_t* sem) {
- if (sem == NULL) {
- errno = EINVAL;
- return -1;
- }
-
uint32_t shared = SEM_GET_SHARED(sem);
while (true) {
@@ -223,11 +209,6 @@
}
int sem_timedwait(sem_t* sem, const timespec* abs_timeout) {
- if (sem == NULL) {
- errno = EINVAL;
- return -1;
- }
-
// POSIX says we need to try to decrement the semaphore
// before checking the timeout value. Note that if the
// value is currently 0, __sem_trydec() does nothing.
@@ -271,10 +252,6 @@
}
int sem_post(sem_t* sem) {
- if (sem == NULL) {
- return EINVAL;
- }
-
uint32_t shared = SEM_GET_SHARED(sem);
ANDROID_MEMBAR_FULL();
@@ -292,11 +269,6 @@
}
int sem_trywait(sem_t* sem) {
- if (sem == NULL) {
- errno = EINVAL;
- return -1;
- }
-
if (__sem_trydec(&sem->count) > 0) {
ANDROID_MEMBAR_FULL();
return 0;
@@ -307,11 +279,6 @@
}
int sem_getvalue(sem_t* sem, int* sval) {
- if (sem == NULL || sval == NULL) {
- errno = EINVAL;
- return -1;
- }
-
int val = SEMCOUNT_TO_VALUE(sem->count);
if (val < 0) {
val = 0;
diff --git a/tests/Android.mk b/tests/Android.mk
index 13d9038..f30a4a8 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -401,8 +401,8 @@
sudo mkdir -p -m 0777 /system/bin; \
fi
mkdir -p $(TARGET_OUT_DATA)/local/tmp
- cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
- cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
+ ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/$(LINKER)` /system/bin
+ ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/sh` /system/bin
ANDROID_DATA=$(TARGET_OUT_DATA) \
ANDROID_ROOT=$(TARGET_OUT) \
LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
@@ -417,8 +417,8 @@
sudo mkdir -p -m 0777 /system/bin; \
fi
mkdir -p $(TARGET_OUT_DATA)/local/tmp
- cp $(TARGET_OUT_EXECUTABLES)/linker /system/bin
- cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
+ ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/linker` /system/bin
+ ln -fs `realpath $(TARGET_OUT_EXECUTABLES)/sh` /system/bin
ANDROID_DATA=$(TARGET_OUT_DATA) \
ANDROID_ROOT=$(TARGET_OUT) \
LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 7585e9b..c5443a8 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -52,7 +52,7 @@
#endif
#define LIBPATH LIBPATH_PREFIX "libdlext_test_fd.so"
-#define LIBZIPPATH LIBPATH_PREFIX "dlext_test.zip"
+#define LIBZIPPATH LIBPATH_PREFIX "libdlext_test_fd_zipaligned.zip"
#define LIBZIP_OFFSET 2*PAGE_SIZE
diff --git a/tests/fortify_sprintf_warnings.cpp b/tests/fortify_sprintf_warnings.cpp
index 2333c3e..3a2d3c4 100644
--- a/tests/fortify_sprintf_warnings.cpp
+++ b/tests/fortify_sprintf_warnings.cpp
@@ -22,12 +22,12 @@
char buf[4];
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___sprintf_chk(char*, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___sprintf_chk(char*, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
sprintf(buf, "foobar"); // NOLINT(runtime/printf)
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___sprintf_chk(char*, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___sprintf_chk(char*, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
sprintf(buf, "%s", "foobar"); // NOLINT(runtime/printf)
}
@@ -36,22 +36,22 @@
char buf[4];
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___snprintf_chk(char*, unsigned int, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
snprintf(buf, 5, "foobar"); // NOLINT(runtime/printf)
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___snprintf_chk(char*, unsigned int, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
snprintf(buf, 5, "%s", "foobar"); // NOLINT(runtime/printf)
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___snprintf_chk(char*, unsigned int, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
snprintf(buf, 5, " %s ", "foobar"); // NOLINT(runtime/printf)
// NOLINTNEXTLINE(whitespace/line_length)
- // GCC: warning: call to int __builtin___snprintf_chk(char*, unsigned int, int, unsigned int, const char*, ...) will always overflow destination buffer
+ // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer
// clang should emit a warning, but doesn't
snprintf(buf, 5, "%d", 100000); // NOLINT(runtime/printf)
}
diff --git a/tests/libs/Android.build.dlext_testzip.mk b/tests/libs/Android.build.dlext_testzip.mk
index e672091..d05927e 100644
--- a/tests/libs/Android.build.dlext_testzip.mk
+++ b/tests/libs/Android.build.dlext_testzip.mk
@@ -18,31 +18,24 @@
# Library used by dlext tests - zipped and aligned
# -----------------------------------------------------------------------------
-# TODO: It there simple way to do this?
-$(bionic_2nd_arch_prefix)bionic_dlext_test_zip := \
- $($(bionic_2nd_arch_prefix)TARGET_OUT_INTERMEDIATES)/libdlext_test_fd/dlext_test_origin.zip
-$(bionic_2nd_arch_prefix)bionic_dlext_test_zip_aligned := \
- $($(bionic_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/libdlext_test_fd/dlext_test.zip
-ALL_MODULES += $($(bionic_2nd_arch_prefix)bionic_dlext_test_zip_aligned)
+include $(CLEAR_VARS)
-$(bionic_2nd_arch_prefix)bionic_dlext_built_shared_libraries := \
- $($(bionic_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/libdlext_test_fd.so
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE := libdlext_test_fd_zipaligned
+LOCAL_MODULE_SUFFIX := .zip
+LOCAL_MODULE_TAGS := tests
+LOCAL_MODULE_PATH := $($(bionic_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/libdlext_test_fd
+LOCAL_2ND_ARCH_VAR_PREFIX := $(bionic_2nd_arch_prefix)
-bionic_dlext_test_zip_alignment := 4096 # PAGE_SIZE
+include $(BUILD_SYSTEM)/base_rules.mk
-$(bionic_2nd_arch_prefix)bionic_dlext_test_zip_tmpdir := $(dir $($(bionic_2nd_arch_prefix)bionic_dlext_test_zip))
+my_shared_libs := \
+ $($(bionic_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/libdlext_test_fd.so
-$($(bionic_2nd_arch_prefix)bionic_dlext_test_zip)_prepare: $($(bionic_2nd_arch_prefix)bionic_dlext_built_shared_libraries)
- $(hide) mkdir -p $(dir $@)
- $(hide) cp -p $< $(dir $@)
-
-$($(bionic_2nd_arch_prefix)bionic_dlext_test_zip): $($(bionic_2nd_arch_prefix)bionic_dlext_test_zip)_prepare
- @echo "Zip: $@"
- $(hide) (cd $(dir $@) && touch empty_file.txt && zip -rD0 $(notdir $@) empty_file.txt libdlext_test_fd.so)
-
-$($(bionic_2nd_arch_prefix)bionic_dlext_test_zip_aligned): $($(bionic_2nd_arch_prefix)bionic_dlext_test_zip) | $(ZIPALIGN)
- $(hide) rm -rf $@
- $(hide) mkdir -p $(dir $@)
- @echo "Zipalign $(bionic_dlext_test_zip_alignment): $@"
- $(hide) zipalign $(bionic_dlext_test_zip_alignment) $< $@
-
+$(LOCAL_BUILT_MODULE): PRIVATE_ALIGNMENT := 4096 # PAGE_SIZE
+$(LOCAL_BUILT_MODULE) : $(my_shared_libs) | $(ZIPALIGN)
+ @echo "Zipalign $(PRIVATE_ALIGNMENT): $@"
+ $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
+ $(hide) cp $^ $(dir $@)
+ $(hide) (cd $(dir $@) && touch empty_file.txt && zip -rD0 $(notdir $@).unaligned empty_file.txt *.so)
+ $(hide) $(ZIPALIGN) $(PRIVATE_ALIGNMENT) $@.unaligned $@