am 69838daa: am d1668a71: Merge "Turn on -Wold-style-cast and fix the errors."

* commit '69838daa8764eb4d008df679e961fb510a37687b':
  Turn on -Wold-style-cast and fix the errors.
This commit is contained in:
Elliott Hughes 2015-01-22 02:02:46 +00:00 committed by Android Git Automerger
commit f7b64d0900
15 changed files with 62 additions and 48 deletions

View File

@ -862,7 +862,7 @@ LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
LOCAL_CLANG_ASFLAGS_arm64 += -no-integrated-as
LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
LOCAL_CPPFLAGS := $(libc_common_cppflags)
LOCAL_CPPFLAGS := $(libc_common_cppflags) -Wold-style-cast
LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
LOCAL_MODULE := libc_bionic
LOCAL_CLANG := $(use_clang)

View File

@ -129,33 +129,34 @@ void __libc_init_common(KernelArgumentBlock& args) {
* entry in the list has value -1, the last one has value 0.
*/
void __libc_fini(void* array) {
void** fini_array = reinterpret_cast<void**>(array);
const size_t minus1 = ~(size_t)0; /* ensure proper sign extension */
typedef void (*Dtor)();
Dtor* fini_array = reinterpret_cast<Dtor*>(array);
const Dtor minus1 = reinterpret_cast<Dtor>(static_cast<uintptr_t>(-1));
/* Sanity check - first entry must be -1 */
if (array == NULL || (size_t)fini_array[0] != minus1) {
// Sanity check - first entry must be -1.
if (array == NULL || fini_array[0] != minus1) {
return;
}
/* skip over it */
// Skip over it.
fini_array += 1;
/* Count the number of destructors. */
// Count the number of destructors.
int count = 0;
while (fini_array[count] != NULL) {
++count;
}
/* Now call each destructor in reverse order. */
// Now call each destructor in reverse order.
while (count > 0) {
void (*func)() = (void (*)()) fini_array[--count];
Dtor dtor = fini_array[--count];
/* Sanity check, any -1 in the list is ignored */
if ((size_t)func == minus1) {
// Sanity check, any -1 in the list is ignored.
if (dtor == minus1) {
continue;
}
func();
dtor();
}
#ifndef LIBC_STATIC

View File

@ -54,7 +54,7 @@ int open(const char* pathname, int flags, ...) {
if ((flags & O_CREAT) != 0) {
va_list args;
va_start(args, flags);
mode = (mode_t) va_arg(args, int);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}
@ -76,7 +76,7 @@ int openat(int fd, const char *pathname, int flags, ...) {
if ((flags & O_CREAT) != 0) {
va_list args;
va_start(args, flags);
mode = (mode_t) va_arg(args, int);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}

View File

@ -62,7 +62,7 @@ void __init_tls(pthread_internal_t* thread) {
thread->tls[TLS_SLOT_SELF] = thread->tls;
thread->tls[TLS_SLOT_THREAD_ID] = thread;
// GCC looks in the TLS for the stack guard on x86, so copy it there from our global.
thread->tls[TLS_SLOT_STACK_GUARD] = (void*) __stack_chk_guard;
thread->tls[TLS_SLOT_STACK_GUARD] = reinterpret_cast<void*>(__stack_chk_guard);
}
void __init_alternate_signal_stack(pthread_internal_t* thread) {

View File

@ -49,7 +49,8 @@ class ScandirResult {
bool Add(dirent* entry) {
if (size_ >= capacity_) {
size_t new_capacity = capacity_ + 32;
dirent** new_names = (dirent**) realloc(names_, new_capacity * sizeof(dirent*));
dirent** new_names =
reinterpret_cast<dirent**>(realloc(names_, new_capacity * sizeof(dirent*)));
if (new_names == NULL) {
return false;
}
@ -68,7 +69,8 @@ class ScandirResult {
void Sort(int (*comparator)(const dirent**, const dirent**)) {
// If we have entries and a comparator, sort them.
if (size_ > 0 && comparator != NULL) {
qsort(names_, size_, sizeof(dirent*), (int (*)(const void*, const void*)) comparator);
qsort(names_, size_, sizeof(dirent*),
reinterpret_cast<int (*)(const void*, const void*)>(comparator));
}
}
@ -80,7 +82,7 @@ class ScandirResult {
static dirent* CopyDirent(dirent* original) {
// Allocate the minimum number of bytes necessary, rounded up to a 4-byte boundary.
size_t size = ((original->d_reclen + 3) & ~3);
dirent* copy = (dirent*) malloc(size);
dirent* copy = reinterpret_cast<dirent*>(malloc(size));
memcpy(copy, original, original->d_reclen);
return copy;
}

View File

@ -31,8 +31,8 @@
int sigaddset(sigset_t* set, int signum) {
int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0.
unsigned long* local_set = (unsigned long*) set;
if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) {
unsigned long* local_set = reinterpret_cast<unsigned long*>(set);
if (set == NULL || bit < 0 || bit >= static_cast<int>(8*sizeof(sigset_t))) {
errno = EINVAL;
return -1;
}

View File

@ -31,8 +31,8 @@
int sigdelset(sigset_t* set, int signum) {
int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0.
unsigned long* local_set = (unsigned long*) set;
if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) {
unsigned long* local_set = reinterpret_cast<unsigned long*>(set);
if (set == NULL || bit < 0 || bit >= static_cast<int>(8*sizeof(sigset_t))) {
errno = EINVAL;
return -1;
}

View File

@ -31,10 +31,10 @@
int sigismember(const sigset_t* set, int signum) {
int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0.
const unsigned long* local_set = (const unsigned long*) set;
if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) {
const unsigned long* local_set = reinterpret_cast<const unsigned long*>(set);
if (set == NULL || bit < 0 || bit >= static_cast<int>(8*sizeof(sigset_t))) {
errno = EINVAL;
return -1;
}
return (int) ((local_set[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1);
return static_cast<int>((local_set[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1);
}

View File

@ -43,7 +43,7 @@ sighandler_t _signal(int signum, sighandler_t handler, int flags) {
return SIG_ERR;
}
return (sighandler_t) sa.sa_handler;
return sa.sa_handler;
}
sighandler_t signal(int signum, sighandler_t handler) {

View File

@ -70,7 +70,7 @@ GLOBAL_INIT_THREAD_LOCAL_BUFFER(passwd);
struct passwd_state_t {
passwd passwd_;
char app_name_buffer_[32];
char name_buffer_[32];
char dir_buffer_[32];
char sh_buffer_[32];
};
@ -141,11 +141,12 @@ int getpwuid_r(uid_t uid, passwd* pwd,
static passwd* android_iinfo_to_passwd(passwd_state_t* state,
const android_id_info* iinfo) {
snprintf(state->name_buffer_, sizeof(state->name_buffer_), "%s", iinfo->name);
snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
passwd* pw = &state->passwd_;
pw->pw_name = (char*) iinfo->name;
pw->pw_name = state->name_buffer_;
pw->pw_uid = iinfo->aid;
pw->pw_gid = iinfo->aid;
pw->pw_dir = state->dir_buffer_;
@ -153,9 +154,12 @@ static passwd* android_iinfo_to_passwd(passwd_state_t* state,
return pw;
}
static group* android_iinfo_to_group(group* gr,
static group* android_iinfo_to_group(group_state_t* state,
const android_id_info* iinfo) {
gr->gr_name = (char*) iinfo->name;
snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_), "%s", iinfo->name);
group* gr = &state->group_;
gr->gr_name = state->group_name_buffer_;
gr->gr_gid = iinfo->aid;
gr->gr_mem[0] = gr->gr_name;
return gr;
@ -179,19 +183,19 @@ static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
return NULL;
}
static group* android_id_to_group(group* gr, unsigned id) {
static group* android_id_to_group(group_state_t* state, unsigned id) {
for (size_t n = 0; n < android_id_count; ++n) {
if (android_ids[n].aid == id) {
return android_iinfo_to_group(gr, android_ids + n);
return android_iinfo_to_group(state, android_ids + n);
}
}
return NULL;
}
static group* android_name_to_group(group* gr, const char* name) {
static group* android_name_to_group(group_state_t* state, const char* name) {
for (size_t n = 0; n < android_id_count; ++n) {
if (!strcmp(android_ids[n].name, name)) {
return android_iinfo_to_group(gr, android_ids + n);
return android_iinfo_to_group(state, android_ids + n);
}
}
return NULL;
@ -268,7 +272,7 @@ static unsigned app_id_from_name(const char* name, bool is_group) {
return 0;
}
return (unsigned)(appid + userid*AID_USER);
return static_cast<unsigned>(appid + userid*AID_USER);
}
static void print_app_name_from_uid(const uid_t uid, char* buffer, const int bufferlen) {
@ -319,7 +323,7 @@ static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
return NULL;
}
print_app_name_from_uid(uid, state->app_name_buffer_, sizeof(state->app_name_buffer_));
print_app_name_from_uid(uid, state->name_buffer_, sizeof(state->name_buffer_));
const uid_t appid = uid % AID_USER;
if (appid < AID_APP) {
@ -331,7 +335,7 @@ static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
passwd* pw = &state->passwd_;
pw->pw_name = state->app_name_buffer_;
pw->pw_name = state->name_buffer_;
pw->pw_dir = state->dir_buffer_;
pw->pw_shell = state->sh_buffer_;
pw->pw_uid = uid;
@ -403,7 +407,7 @@ group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
return NULL;
}
group* gr = android_id_to_group(&state->group_, gid);
group* gr = android_id_to_group(state, gid);
if (gr != NULL) {
return gr;
}
@ -416,7 +420,7 @@ group* getgrnam(const char* name) { // NOLINT: implementing bad function.
return NULL;
}
if (android_name_to_group(&state->group_, name) != 0) {
if (android_name_to_group(state, name) != 0) {
return &state->group_;
}
return app_id_to_group(app_id_from_name(name, true), state);

View File

@ -83,29 +83,29 @@ int get_nprocs() {
return result;
}
static int __get_meminfo(const char* pattern) {
static int __get_meminfo_page_count(const char* pattern) {
FILE* fp = fopen("/proc/meminfo", "re");
if (fp == NULL) {
return -1;
}
int result = -1;
int page_count = -1;
char buf[256];
while (fgets(buf, sizeof(buf), fp) != NULL) {
long total;
if (sscanf(buf, pattern, &total) == 1) {
result = (int) (total / (PAGE_SIZE/1024));
page_count = static_cast<int>(total / (PAGE_SIZE / 1024));
break;
}
}
fclose(fp);
return result;
return page_count;
}
long get_phys_pages() {
return __get_meminfo("MemTotal: %ld kB");
return __get_meminfo_page_count("MemTotal: %ld kB");
}
long get_avphys_pages() {
return __get_meminfo("MemFree: %ld kB");
return __get_meminfo_page_count("MemFree: %ld kB");
}

View File

@ -21,7 +21,7 @@
// Destroy a tree and free all allocated resources.
// This is a GNU extension, not available from BSD.
void tdestroy(void* root, void (*destroy_func)(void*)) {
node_t* root_node = (node_t*) root;
node_t* root_node = reinterpret_cast<node_t*>(root);
if (root_node == NULL) {
return;
}

View File

@ -52,13 +52,13 @@ static vdso_entry vdso_entries[] = {
int clock_gettime(int clock_id, timespec* tp) {
static int (*vdso_clock_gettime)(int, timespec*) =
(int (*)(int, timespec*)) vdso_entries[VDSO_CLOCK_GETTIME].fn;
reinterpret_cast<int (*)(int, timespec*)>(vdso_entries[VDSO_CLOCK_GETTIME].fn);
return vdso_clock_gettime(clock_id, tp);
}
int gettimeofday(timeval* tv, struct timezone* tz) {
static int (*vdso_gettimeofday)(timeval*, struct timezone*) =
(int (*)(timeval*, struct timezone*)) vdso_entries[VDSO_GETTIMEOFDAY].fn;
reinterpret_cast<int (*)(timeval*, struct timezone*)>(vdso_entries[VDSO_GETTIMEOFDAY].fn);
return vdso_gettimeofday(tv, tz);
}

View File

@ -47,7 +47,12 @@ struct __sfileext {
bool _stdio_handles_locking; /* __fsetlocking support */
};
#if defined(__cplusplus)
#define _EXT(fp) reinterpret_cast<__sfileext*>((fp)->_ext._base)
#else
#define _EXT(fp) ((struct __sfileext *)((fp)->_ext._base))
#endif
#define _UB(fp) _EXT(fp)->_ub
#define _FLOCK(fp) _EXT(fp)->_lock

View File

@ -124,6 +124,7 @@ extern void __atexit_register_cleanup(void (*)(void));
#define __sferror(p) (((p)->_flags & __SERR) != 0)
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
#define __sfileno(p) ((p)->_file)
#if !defined(__cplusplus)
#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
static __inline int __sputc(int _c, FILE* _p) {
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) {
@ -132,6 +133,7 @@ static __inline int __sputc(int _c, FILE* _p) {
return (__swbuf(_c, _p));
}
}
#endif
/* OpenBSD declares these in fvwrite.h but we want to ensure they're hidden. */
struct __suio;