1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/socket.c (tcp_s_gethostbyname): was using

uninitialized size_t value. [ruby-talk:76946]

* Minor cleanups.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-07-25 05:36:55 +00:00
parent 43601a1d17
commit 85911c410a
14 changed files with 55 additions and 48 deletions

View file

@ -1,3 +1,8 @@
Fri Jul 25 14:34:55 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (tcp_s_gethostbyname): was using
uninitialized size_t value. [ruby-talk:76946]
Fri Jul 25 13:38:38 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net> Fri Jul 25 13:38:38 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* re.c (rb_reg_options_m): use rb_reg_options() to mask internal * re.c (rb_reg_options_m): use rb_reg_options() to mask internal

View file

@ -1817,7 +1817,7 @@ rb_ary_and(ary1, ary2)
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
VALUE v = RARRAY(ary1)->ptr[i]; VALUE v = RARRAY(ary1)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, (st_data_t*)&v, 0)) {
rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
} }
} }
@ -1839,13 +1839,13 @@ rb_ary_or(ary1, ary2)
for (i=0; i<RARRAY(ary1)->len; i++) { for (i=0; i<RARRAY(ary1)->len; i++) {
v = RARRAY(ary1)->ptr[i]; v = RARRAY(ary1)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, (st_data_t*)&v, 0)) {
rb_ary_push(ary3, RARRAY(ary1)->ptr[i]); rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
} }
} }
for (i=0; i<RARRAY(ary2)->len; i++) { for (i=0; i<RARRAY(ary2)->len; i++) {
v = RARRAY(ary2)->ptr[i]; v = RARRAY(ary2)->ptr[i];
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, (st_data_t*)&v, 0)) {
rb_ary_push(ary3, RARRAY(ary2)->ptr[i]); rb_ary_push(ary3, RARRAY(ary2)->ptr[i]);
} }
} }
@ -1870,7 +1870,7 @@ rb_ary_uniq_bang(ary)
end = p + RARRAY(ary)->len; end = p + RARRAY(ary)->len;
while (p < end) { while (p < end) {
VALUE v = *p; VALUE v = *p;
if (st_delete(RHASH(hash)->tbl, &v, 0)) { if (st_delete(RHASH(hash)->tbl, (st_data_t*)&v, 0)) {
*q++ = *p; *q++ = *p;
} }
p++; p++;

View file

@ -72,9 +72,9 @@ rb_mod_clone(module)
RCLASS(clone)->iv_tbl = st_copy(RCLASS(module)->iv_tbl); RCLASS(clone)->iv_tbl = st_copy(RCLASS(module)->iv_tbl);
id = rb_intern("__classpath__"); id = rb_intern("__classpath__");
st_delete(RCLASS(clone)->iv_tbl, &id, 0); st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
id = rb_intern("__classid__"); id = rb_intern("__classid__");
st_delete(RCLASS(clone)->iv_tbl, &id, 0); st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
} }
if (RCLASS(module)->m_tbl) { if (RCLASS(module)->m_tbl) {
RCLASS(clone)->m_tbl = st_init_numtable(); RCLASS(clone)->m_tbl = st_init_numtable();

6
dln.c
View file

@ -675,7 +675,7 @@ load_1(fd, disp, need_init)
char *key = sym->n_un.n_name; char *key = sym->n_un.n_name;
if (st_lookup(sym_tbl, sym[1].n_un.n_name, &old_sym)) { if (st_lookup(sym_tbl, sym[1].n_un.n_name, &old_sym)) {
if (st_delete(undef_tbl, &key, NULL)) { if (st_delete(undef_tbl, (st_data_t*)&key, NULL)) {
unlink_undef(key, old_sym->n_value); unlink_undef(key, old_sym->n_value);
free(key); free(key);
} }
@ -688,7 +688,7 @@ load_1(fd, disp, need_init)
st_foreach(reloc_tbl, reloc_repl, &data); st_foreach(reloc_tbl, reloc_repl, &data);
st_insert(undef_tbl, strdup(sym[1].n_un.n_name), NULL); st_insert(undef_tbl, strdup(sym[1].n_un.n_name), NULL);
if (st_delete(undef_tbl, &key, NULL)) { if (st_delete(undef_tbl, (st_data_t*)&key, NULL)) {
free(key); free(key);
} }
} }
@ -756,7 +756,7 @@ load_1(fd, disp, need_init)
} }
key = sym->n_un.n_name; key = sym->n_un.n_name;
if (st_delete(undef_tbl, &key, NULL) != 0) { if (st_delete(undef_tbl, (st_data_t*)&key, NULL) != 0) {
unlink_undef(key, sym->n_value); unlink_undef(key, sym->n_value);
free(key); free(key);
} }

14
eval.c
View file

@ -8206,7 +8206,7 @@ rb_thread_save_context(th)
} }
static int static int
thread_switch(n) rb_thread_switch(n)
int n; int n;
{ {
rb_trap_immediate = (curr_thread->flags&0x100)?1:0; rb_trap_immediate = (curr_thread->flags&0x100)?1:0;
@ -8239,7 +8239,7 @@ thread_switch(n)
#define THREAD_SAVE_CONTEXT(th) \ #define THREAD_SAVE_CONTEXT(th) \
(rb_thread_save_context(th),\ (rb_thread_save_context(th),\
thread_switch((FLUSH_REGISTER_WINDOWS, setjmp((th)->context)))) rb_thread_switch((FLUSH_REGISTER_WINDOWS, setjmp((th)->context))))
static void rb_thread_restore_context _((rb_thread_t,int)); static void rb_thread_restore_context _((rb_thread_t,int));
@ -9137,13 +9137,13 @@ rb_thread_safe_level(thread)
return INT2NUM(th->safe); return INT2NUM(th->safe);
} }
static int thread_abort; static int ruby_thread_abort;
static VALUE thgroup_default; static VALUE thgroup_default;
static VALUE static VALUE
rb_thread_s_abort_exc() rb_thread_s_abort_exc()
{ {
return thread_abort?Qtrue:Qfalse; return ruby_thread_abort?Qtrue:Qfalse;
} }
static VALUE static VALUE
@ -9151,7 +9151,7 @@ rb_thread_s_abort_exc_set(self, val)
VALUE self, val; VALUE self, val;
{ {
rb_secure(4); rb_secure(4);
thread_abort = RTEST(val); ruby_thread_abort = RTEST(val);
return val; return val;
} }
@ -9380,7 +9380,7 @@ rb_thread_start_0(fn, arg, th_arg)
rb_thread_raise(1, &ruby_errinfo, main_thread); rb_thread_raise(1, &ruby_errinfo, main_thread);
} }
} }
else if (th->safe < 4 && (thread_abort || th->abort || RTEST(ruby_debug))) { else if (th->safe < 4 && (ruby_thread_abort || th->abort || RTEST(ruby_debug))) {
VALUE err = system_exit(1, 0, 0); VALUE err = system_exit(1, 0, 0);
error_print(); error_print();
/* exit on main_thread */ /* exit on main_thread */
@ -9733,7 +9733,7 @@ rb_thread_local_aset(thread, id, val)
th->locals = st_init_numtable(); th->locals = st_init_numtable();
} }
if (NIL_P(val)) { if (NIL_P(val)) {
st_delete(th->locals, &id, 0); st_delete(th->locals, (st_data_t*)&id, 0);
return Qnil; return Qnil;
} }
st_insert(th->locals, id, val); st_insert(th->locals, id, val);

View file

@ -1092,7 +1092,6 @@ tcp_s_gethostbyname(obj, host)
struct hostent *h = sock_hostbyname(host); struct hostent *h = sock_hostbyname(host);
VALUE ary, names; VALUE ary, names;
char **pch; char **pch;
size_t size;
ary = rb_ary_new(); ary = rb_ary_new();
rb_ary_push(ary, rb_str_new2(h->h_name)); rb_ary_push(ary, rb_str_new2(h->h_name));
@ -1124,7 +1123,7 @@ tcp_s_gethostbyname(obj, host)
#ifdef SIN6_LEN #ifdef SIN6_LEN
sin6.sin6_len = sizeof(sin6); sin6.sin6_len = sizeof(sin6);
#endif #endif
memcpy((char*)&sin6.sin6_addr, *pch, size); memcpy((char*)&sin6.sin6_addr, *pch, h->h_length);
rb_ary_push(ary, mkipaddr((struct sockaddr*)&sin6)); rb_ary_push(ary, mkipaddr((struct sockaddr*)&sin6));
break; break;
} }

View file

@ -192,7 +192,7 @@ syck_emitter_flush( SyckEmitter *e, long check_room )
{ {
char *header = S_ALLOC_N( char, 64 ); char *header = S_ALLOC_N( char, 64 );
S_MEMZERO( header, char, 64 ); S_MEMZERO( header, char, 64 );
sprintf( header, "--- %YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR ); sprintf( header, "--- %%YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR );
(e->handler)( e, header, strlen( header ) ); (e->handler)( e, header, strlen( header ) );
S_FREE( header ); S_FREE( header );
} }

1
file.c
View file

@ -1051,6 +1051,7 @@ rb_file_s_lchmod(argc, argv)
VALUE *argv; VALUE *argv;
{ {
rb_notimplement(); rb_notimplement();
return Qnil; /* not reached */
} }
#endif #endif

4
gc.c
View file

@ -1459,7 +1459,7 @@ undefine_final(os, obj)
VALUE os, obj; VALUE os, obj;
{ {
if (finalizer_table) { if (finalizer_table) {
st_delete(finalizer_table, &obj, 0); st_delete(finalizer_table, (st_data_t*)&obj, 0);
} }
return obj; return obj;
} }
@ -1533,7 +1533,7 @@ run_final(obj)
args[0] = RARRAY(finalizers)->ptr[i]; args[0] = RARRAY(finalizers)->ptr[i];
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status); rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
} }
if (finalizer_table && st_delete(finalizer_table, &obj, &table)) { if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
for (i=0; i<RARRAY(table)->len; i++) { for (i=0; i<RARRAY(table)->len; i++) {
args[0] = RARRAY(table)->ptr[i]; args[0] = RARRAY(table)->ptr[i];
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status); rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);

4
hash.c
View file

@ -407,12 +407,12 @@ rb_hash_delete(hash, key)
rb_hash_modify(hash); rb_hash_modify(hash);
if (RHASH(hash)->iter_lev > 0) { if (RHASH(hash)->iter_lev > 0) {
if (st_delete_safe(RHASH(hash)->tbl, &key, &val, Qundef)) { if (st_delete_safe(RHASH(hash)->tbl, (st_data_t*)&key, &val, Qundef)) {
FL_SET(hash, HASH_DELETED); FL_SET(hash, HASH_DELETED);
return val; return val;
} }
} }
else if (st_delete(RHASH(hash)->tbl, &key, &val)) else if (st_delete(RHASH(hash)->tbl, (st_data_t*)&key, &val))
return val; return val;
if (rb_block_given_p()) { if (rb_block_given_p()) {
return rb_yield(key); return rb_yield(key);

View file

@ -117,7 +117,7 @@ class Rational
Unify = true Unify = true
def inspect def inspect
format "%s/%s", @numerator.inspect, @denominator.inspect format "%s/%s", numerator.inspect, denominator.inspect
end end
alias power! ** alias power! **
@ -134,8 +134,8 @@ class Rational
return Rational(1,1) return Rational(1,1)
end end
npd = @numerator.prime_division npd = numerator.prime_division
dpd = @denominator.prime_division dpd = denominator.prime_division
if other < 0 if other < 0
other = -other other = -other
npd, dpd = dpd, npd npd, dpd = dpd, npd
@ -164,11 +164,11 @@ class Rational
elsif other.kind_of?(Integer) elsif other.kind_of?(Integer)
if other > 0 if other > 0
num = @numerator ** other num = numerator ** other
den = @denominator ** other den = denominator ** other
elsif other < 0 elsif other < 0
num = @denominator ** -other num = denominator ** -other
den = @numerator ** -other den = numerator ** -other
elsif other == 0 elsif other == 0
num = 1 num = 1
den = 1 den = 1
@ -208,11 +208,11 @@ class Rational
elsif other.kind_of?(Integer) elsif other.kind_of?(Integer)
if other > 0 if other > 0
num = @numerator ** other num = numerator ** other
den = @denominator ** other den = denominator ** other
elsif other < 0 elsif other < 0
num = @denominator ** -other num = denominator ** -other
den = @numerator ** -other den = numerator ** -other
elsif other == 0 elsif other == 0
num = 1 num = 1
den = 1 den = 1

View file

@ -11,6 +11,7 @@
**********************************************************************/ **********************************************************************/
#include "ruby.h" #include "ruby.h"
#include "env.h"
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
@ -131,7 +132,7 @@ rb_num_coerce_bin(x, y)
VALUE x, y; VALUE x, y;
{ {
do_coerce(&x, &y, Qtrue); do_coerce(&x, &y, Qtrue);
return rb_funcall(x, rb_frame_last_func(), 1, y); return rb_funcall(x, ruby_frame->orig_func, 1, y);
} }
VALUE VALUE
@ -139,7 +140,7 @@ rb_num_coerce_cmp(x, y)
VALUE x, y; VALUE x, y;
{ {
if (do_coerce(&x, &y, Qfalse)) if (do_coerce(&x, &y, Qfalse))
return rb_funcall(x, rb_frame_last_func(), 1, y); return rb_funcall(x, ruby_frame->orig_func, 1, y);
return Qnil; return Qnil;
} }
@ -150,7 +151,7 @@ num_coerce_relop(x, y)
VALUE c, x0 = x, y0 = y; VALUE c, x0 = x, y0 = y;
if (!do_coerce(&x, &y, Qfalse) || if (!do_coerce(&x, &y, Qfalse) ||
NIL_P(c = rb_funcall(x, rb_frame_last_func(), 1, y))) { NIL_P(c = rb_funcall(x, ruby_frame->orig_func, 1, y))) {
rb_cmperr(x0, y0); rb_cmperr(x0, y0);
return Qnil; /* not reached */ return Qnil; /* not reached */
} }

View file

@ -297,7 +297,7 @@ rb_waitpid(pid, st, flags)
#else /* NO_WAITPID */ #else /* NO_WAITPID */
if (pid_tbl && st_lookup(pid_tbl, pid, st)) { if (pid_tbl && st_lookup(pid_tbl, pid, st)) {
last_status_set(*st, pid); last_status_set(*st, pid);
st_delete(pid_tbl, &pid, NULL); st_delete(pid_tbl, (st_data_t*)&pid, NULL);
return pid; return pid;
} }
@ -1487,6 +1487,7 @@ p_sys_issetugid(obj)
} }
#else #else
rb_notimplement(); rb_notimplement();
return Qnil; /* not reached */
#endif #endif
} }

View file

@ -155,7 +155,7 @@ classname(klass)
} }
path = rb_str_new2(rb_id2name(SYM2ID(path))); path = rb_str_new2(rb_id2name(SYM2ID(path)));
st_insert(ROBJECT(klass)->iv_tbl, classpath, path); st_insert(ROBJECT(klass)->iv_tbl, classpath, path);
st_delete(RCLASS(klass)->iv_tbl, &classid, 0); st_delete(RCLASS(klass)->iv_tbl, (st_data_t*)&classid, 0);
} }
if (TYPE(path) != T_STRING) { if (TYPE(path) != T_STRING) {
rb_bug("class path is not set properly"); rb_bug("class path is not set properly");
@ -188,7 +188,7 @@ rb_class_path(klass)
path = find_class_path(klass); path = find_class_path(klass);
if (!NIL_P(path)) { if (!NIL_P(path)) {
st_delete(RCLASS(klass)->iv_tbl, &tmppath, 0); st_delete(RCLASS(klass)->iv_tbl, (st_data_t*)&tmppath, 0);
return path; return path;
} }
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, tmppath, &path)) { if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, tmppath, &path)) {
@ -1085,7 +1085,7 @@ rb_obj_remove_instance_variable(obj, name)
case T_OBJECT: case T_OBJECT:
case T_CLASS: case T_CLASS:
case T_MODULE: case T_MODULE:
if (ROBJECT(obj)->iv_tbl && st_delete(ROBJECT(obj)->iv_tbl, &id, &val)) { if (ROBJECT(obj)->iv_tbl && st_delete(ROBJECT(obj)->iv_tbl, (st_data_t*)&id, &val)) {
return val; return val;
} }
break; break;
@ -1184,17 +1184,17 @@ autoload_delete(mod, id)
{ {
VALUE val, file = Qnil; VALUE val, file = Qnil;
st_delete(RCLASS(mod)->iv_tbl, &id, 0); st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, 0);
if (st_lookup(RCLASS(mod)->iv_tbl, autoload, &val)) { if (st_lookup(RCLASS(mod)->iv_tbl, autoload, &val)) {
struct st_table *tbl = check_autoload_table(val); struct st_table *tbl = check_autoload_table(val);
if (!st_delete(tbl, &id, &file)) file = Qnil; if (!st_delete(tbl, (st_data_t*)&id, &file)) file = Qnil;
if (tbl->num_entries == 0) { if (tbl->num_entries == 0) {
DATA_PTR(val) = 0; DATA_PTR(val) = 0;
st_free_table(tbl); st_free_table(tbl);
id = autoload; id = autoload;
if (st_delete(RCLASS(mod)->iv_tbl, &id, &val)) { if (st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, &val)) {
rb_gc_force_recycle(val); rb_gc_force_recycle(val);
} }
} }
@ -1242,12 +1242,12 @@ autoload_file(mod, id)
} }
/* already loaded but not defined */ /* already loaded but not defined */
st_delete(tbl, &id, 0); st_delete(tbl, (st_data_t*)&id, 0);
if (!tbl->num_entries) { if (!tbl->num_entries) {
DATA_PTR(val) = 0; DATA_PTR(val) = 0;
st_free_table(tbl); st_free_table(tbl);
id = autoload; id = autoload;
if (st_delete(RCLASS(mod)->iv_tbl, &id, &val)) { if (st_delete(RCLASS(mod)->iv_tbl, (st_data_t*)&id, &val)) {
rb_gc_force_recycle(val); rb_gc_force_recycle(val);
} }
} }
@ -1349,7 +1349,7 @@ rb_mod_remove_const(mod, name)
rb_raise(rb_eSecurityError, "Insecure: can't remove constant"); rb_raise(rb_eSecurityError, "Insecure: can't remove constant");
if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module");
if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &id, &val)) { if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, (st_data_t*)&id, &val)) {
if (val == Qundef) { if (val == Qundef) {
autoload_delete(mod, id); autoload_delete(mod, id);
val = Qnil; val = Qnil;
@ -1750,7 +1750,7 @@ rb_mod_remove_cvar(mod, name)
rb_raise(rb_eSecurityError, "Insecure: can't remove class variable"); rb_raise(rb_eSecurityError, "Insecure: can't remove class variable");
if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module");
if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &id, &val)) { if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, (st_data_t*)&id, &val)) {
return val; return val;
} }
if (rb_cvar_defined(mod, id)) { if (rb_cvar_defined(mod, id)) {