MESSAGE
DATE | 2016-11-29 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] witmer lab ohio and 3d imaging
|
From learn-bounces-at-nylxs.com Tue Nov 29 19:48:22 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id A9613161312; Tue, 29 Nov 2016 19:48:22 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 4CB90160E77; Tue, 29 Nov 2016 19:48:20 -0500 (EST) To: Christopher League , Hangout , learn-at-nylxs.com References: <32e7ca42-85ec-7594-f6cf-5d0a0bf3a8fc-at-mrbrklyn.com> <87wpflx55t.fsf-at-contrapunctus.net> From: Ruben Safir Message-ID: Date: Tue, 29 Nov 2016 19:48:20 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <87wpflx55t.fsf-at-contrapunctus.net> Subject: [Learn] witmer lab ohio and 3d imaging X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
On 11/29/2016 06:00 PM, Christopher League wrote: > > First thing I try to do is to reduce the program to the SMALLEST program > that reproduces the same error. You can think of it as binary search: > delete (something like) HALF the program. If error is not reproduced, > restore that half and delete the OTHER HALF. If error is reproduced, > then delete half AGAIN. Continue until it's as small as possible. Here's > the minimal crashing program I came up with: > > int main ( int argc, char *argv[] ) > { > std::vector test {0}; > assert(test.size() == 1); // VECTOR HAS JUST ONE ELEMENT! > for(int i = 0; i<10; i++ ){ > test[i] = i; // THEREFORE THIS IS AN ERROR WHEN i>0 > } > return 0; > } > > It exhibits the same error yours does: "free(): invalid next size > (fast)". I added the `assert` to test my assumption about what the `{0}` > initializer means. > > I tried going even further by unrolling and 'sampling' the loop: > > int main ( int argc, char *argv[] ) > { > std::vector test {0}; > assert(test.size() == 1); // VECTOR HAS JUST ONE ELEMENT! > test[0] = 0; // SAFE > test[1] = 1; // ERR > test[9] = 9; // ERR > return 0; > } > > But this -- unfortunately, IMO -- does not crash. Nevertheless, It's > still erroneous. It's ABSOLUTELY NOT ALLOWED to read or write `test[1]` > or `test[9]` because `test.size() == 1`. > > Anyway, the `vector` type HAS a dereference operation that does > bounds-checking. You'll be much better off if you USE IT. That would > look like this: > > int main ( int argc, char *argv[] ) > { > std::vector test {0}; > assert(test.size() == 1); // VECTOR HAS JUST ONE ELEMENT! > test.at(0) = 0; // SAFE > test.at(1) = 1; // CRASH! > test.at(9) = 9; // UNREACHABLE > return 0; > } > > This time it crashes with a much more helpful error message: > > terminate called after throwing an instance of 'std::out_of_range' > what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 1) > > and if you back-trace in `gdb` it pinpoints exactly where the error is. > (Unlike with your initial error, when it actually crashes AFTER the > actual erroneous access.) > > Due to the bounds-checking, you haven't overwritten any of the memory > management record-keeping, so it can give you honest results. > > If you don't like bounds-checking, TOUGH... do it anyway. ONCE THE > PROGRAM IS WORKING, you can optimize it away where you really think you > need to. (Usually you don't.) > > That's my $0.03. > > CL >
http://www.ohio.edu/people/witmerl/lab.htm
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|