From: Michal Rokos Date: 2002-08-23T21:56:02+09:00 Subject: [Cleanup?] File (struct stat handling) Hello, when I tried to track down all remaining off_t leftovers, I saw (at least I think) not so safe struct stat handling. Could you look at it? Thank you. Michal PS: Don't worry - no more patches are comming (It's weekend and BankHoliday monday) :-) Index: file.c =================================================================== RCS file: /src/ruby/file.c,v retrieving revision 1.105 diff -u -p -r1.105 file.c --- file.c 2002/08/21 15:47:54 1.105 +++ file.c 2002/08/23 12:46:08 @@ -122,7 +122,7 @@ stat_new_0(klass, st) if (st) { nst = ALLOC(struct stat); - *nst = *st; + memcpy(nst, st, sizeof(struct stat)); } return Data_Wrap_Struct(klass, NULL, free, nst); } @@ -2007,8 +2007,12 @@ rb_stat_init(obj, fname) if (stat(RSTRING(fname)->ptr, &st) == -1) { rb_sys_fail(RSTRING(fname)->ptr); } + if (DATA_PTR(obj)) { + free(DATA_PTR(obj)); + DATA_PTR(obj) = NULL; + } nst = ALLOC(struct stat); - *nst = st; + memcpy(nst, &st, sizeof(struct stat)); DATA_PTR(obj) = nst; return Qnil; @@ -2024,12 +2028,11 @@ rb_stat_clone(obj) clone = rb_obj_alloc(RBASIC(obj)->klass); CLONESETUP(clone,obj); + if (DATA_PTR(obj)) { nst = ALLOC(struct stat); - *nst = *(struct stat*)DATA_PTR(obj); - DATA_PTR(clone) = nst; + memcpy(DATA_PTR(clone), DATA_PTR(obj), sizeof(struct stat)); } - return clone; } -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Michal Rokos Czech Technical University, Prague E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.cz -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-