Return-Path: william@bourbon.usc.edu Delivery-Date: Thu Sep 25 08:25:09 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m8PFP9RG014680 for ; Thu, 25 Sep 2008 08:25:09 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m8PFSGQ1018920 for ; Thu, 25 Sep 2008 08:28:16 -0700 Message-Id: <200809251528.m8PFSGQ1018920@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS551: warmup2 , realloc issue Date: Thu, 25 Sep 2008 08:28:16 -0700 From: Bill Cheng Someone wrote: > I am getting a bus error while using realloc. > > This is the part of code where i am getting a bus error. > customernum is changed in every loop iteration > ProcessedQ[customernum-1] = MainQ->cust; > /*This line gives bus error*/ > ProcessedQ = (customer *) realloc (ProcessedQ,(customernum + > 1)*sizeof(struct customer)); > > Is this an issue with realloc ? or some other issue. Please read: http://merlot.usc.edu/cs551-f08/projects.html#segfault Seg faults is often caused by memory corruption. So, the bug can be somewhere else and not at the instruction that shows up the crash. In your code, clearly, if customernum is zero, you can corrupt memory. -- Bill Cheng // bill.cheng@usc.edu