Permalink
Browse files

Fix a number of warnings exposed by http://clang-analyzer.llvm.org

This fixes a number of issues that are either actual issues or trivial
to fix / change.
  • Loading branch information...
1 parent f794c30 commit 0a7cea326e532e4bbc1b3e59e639a8ac90d5557b @dbussink dbussink committed Jan 12, 2013
View
@@ -1,10 +1,14 @@
#ifndef RBX_BUG_HPP
#define RBX_BUG_HPP
+#ifndef NORETURN
+#define NORETURN(x) __attribute__ ((noreturn)) x
+#endif
+
namespace rubinius {
- void abort();
- void bug(const char* message);
- void bug(const char* message, const char* arg);
+ NORETURN(void abort());
+ NORETURN(void bug(const char* message));
+ NORETURN(void bug(const char* message, const char* arg));
void warn(const char* message);
void print_backtrace(size_t max=100);
}
View
@@ -608,7 +608,10 @@ namespace rubinius {
return NULL;
}
- if(bytes_read == 0) return cNil;
+ if(bytes_read == 0) {
+ if(malloc_buf) free(malloc_buf);
+ return cNil;
+ }
String* str = String::create(state, buf, bytes_read);
if(malloc_buf) free(malloc_buf);
View
@@ -102,7 +102,7 @@ namespace rubinius {
ListNode* node = first_;
ListNode* lst = nil<ListNode>();
- ListNode* nxt = nil<ListNode>();
+ ListNode* nxt;
while(!node->nil_p()) {
nxt = node->next();
View
@@ -395,7 +395,7 @@ namespace rubinius {
class_name = class_name.substr(k);
}
- bool found;
+ bool found = false;
Object* obj = G(mirror)->get_const(state, state->symbol(class_name), &found);
if(found) {
@@ -722,8 +722,8 @@ namespace rubinius {
size_t ffi_index = 0;
size_t obj_index = 0;
- void* values[ffi_data->arg_count];
- void* heap_allocations[ffi_data->arg_count];
+ void* values[arg_count];
+ void* heap_allocations[arg_count];
for(size_t i = 0; i < arg_count; i++) {
heap_allocations[i] = 0;
}
@@ -765,9 +765,9 @@ namespace rubinius {
Exception::make_exception(state, G(exc_arg), msg.str().c_str());
exc->locations(state, Location::from_call_stack(state, call_frame));
state->raise_exception(exc);
- for(ffi_index = 0; ffi_index < arg_count; ffi_index++) {
- if (heap_allocations[ffi_index]) {
- XFREE(heap_allocations[ffi_index]);
+ for(size_t i = 0; i < arg_count; i++) {
+ if (heap_allocations[i]) {
+ XFREE(heap_allocations[i]);
}
}
return NULL;
@@ -925,9 +925,9 @@ namespace rubinius {
} else if(CBOOL(obj->respond_to(state, state->symbol("to_ptr"), cTrue))) {
Object* o2 = obj->send(state, call_frame, state->symbol("to_ptr"));
if(!o2) {
- for(ffi_index = 0; ffi_index < arg_count; ffi_index++) {
- if (heap_allocations[ffi_index]) {
- XFREE(heap_allocations[ffi_index]);
+ for(size_t i = 0; i < arg_count; i++) {
+ if (heap_allocations[i]) {
+ XFREE(heap_allocations[i]);
}
}
return 0;
@@ -954,9 +954,9 @@ namespace rubinius {
ary->set(state, 0, obj);
Object* val = arg_info->enum_obj->send(state, call_frame, state->symbol("[]"), ary);
if(!val) {
- for(ffi_index = 0; ffi_index < arg_count; ffi_index++) {
- if (heap_allocations[ffi_index]) {
- XFREE(heap_allocations[ffi_index]);
+ for(size_t i = 0; i < arg_count; i++) {
+ if (heap_allocations[i]) {
+ XFREE(heap_allocations[i]);
}
}
return 0;
@@ -1206,9 +1206,9 @@ namespace rubinius {
env->set_current_call_frame(saved_frame);
- for(ffi_index = 0; ffi_index < ffi_data_local->arg_count; ffi_index++) {
- if (heap_allocations[ffi_index]) {
- XFREE(heap_allocations[ffi_index]);
+ for(size_t i = 0; i < arg_count; i++) {
+ if (heap_allocations[i]) {
+ XFREE(heap_allocations[i]);
}
}
View
@@ -842,8 +842,6 @@ namespace rubinius {
if(ByteArray* reg_tmp = force_as<ByteArray>(mark.call(reg_ba))) {
reg_o->onig_data = reinterpret_cast<regex_t*>(reg_tmp->raw_bytes());
mark.just_set(obj, reg_tmp);
-
- reg_ba = reg_tmp;
reg = reg_o->onig_data;
}
View
@@ -21,8 +21,6 @@ namespace rubinius {
namespace capi {
Array* capi_get_array(NativeMethodEnvironment* env, VALUE val) {
- if(!env) env = NativeMethodEnvironment::get();
-
Handle* handle = Handle::from(val);
Array* array = c_as<Array>(handle->object());
handle->flush(env);
@@ -31,8 +29,6 @@ namespace rubinius {
}
void capi_update_array(NativeMethodEnvironment* env, VALUE array) {
- if(!env) env = NativeMethodEnvironment::get();
-
Handle::from(array)->update(env);
}
View
@@ -37,10 +37,10 @@ namespace rubinius {
std::string& capi_get_constant_name(int type);
/** Raise a RuntimeError error */
- void capi_raise_runtime_error(const char* reason);
+ NORETURN(void capi_raise_runtime_error(const char* reason));
/** Raise a TypeError (convenience method). */
- void capi_raise_type_error(object_type type, Object* object);
+ NORETURN(void capi_raise_type_error(object_type type, Object* object));
/** Raise backend */
void capi_raise_backend(Exception* exception);
View
@@ -186,7 +186,7 @@ extern "C" {
int rb_to_encoding_index(VALUE obj) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
- Encoding* enc = nil<Encoding>();
+ Encoding* enc;
switch(TYPE(obj)) {
case T_ENCODING:
View
@@ -17,8 +17,6 @@ namespace rubinius {
namespace capi {
String* capi_get_string(NativeMethodEnvironment* env, VALUE string) {
- if(!env) env = NativeMethodEnvironment::get();
-
Handle* handle = Handle::from(string);
String* str = c_as<String>(handle->object());
handle->flush(env);
@@ -27,8 +25,6 @@ namespace rubinius {
}
void capi_update_string(NativeMethodEnvironment* env, VALUE string) {
- if(!env) env = NativeMethodEnvironment::get();
-
Handle* handle = Handle::from(string);
handle->update(env);
}
View
@@ -111,13 +111,10 @@ namespace rubinius {
}
}
-
- static bool hard_abort = true;
-
void abort() {
std::cout << "Abort!" << std::endl;
print_backtrace();
- if(hard_abort) ::abort();
+ ::abort();
}
void bug(const char* message) {
View
@@ -2950,8 +2950,6 @@ namespace rubinius {
// Now, change jbb to point to code, so anyone branching there hits
// the check first.
jbb.prologue = code;
- } else {
- code = jbb.block;
}
}

0 comments on commit 0a7cea3

Please sign in to comment.