Thread View: comp.unix.programmer
7 messages
7 total messages
Started by cal
Thu, 17 Jan 2002 20:24
crashes on char[]
Author: cal
Date: Thu, 17 Jan 2002 20:24
Date: Thu, 17 Jan 2002 20:24
7 lines
1183 bytes
1183 bytes
Hi there,
My program crashes whenever I use char array, eg,
char data[1024];
then the program will crash (memory fault)...... It is a multi-threads
program. I used gcc302 on HP11............
Re: crashes on char[]
Author: John Gordon217-352-6511x7418CEER...
Date: Thu, 17 Jan 2002 20:46
Date: Thu, 17 Jan 2002 20:46
14 lines
1373 bytes
1373 bytes
"cal" <ccheng@cybermation.com> writes: > Hi there, > My program crashes whenever I use char array, eg, > char data[1024]; you're probably copying too many characters into the array. post your code, and we might be able to help you further. --- John Gordon "No Silicon Heaven? Preposterous! Where would gordon@osiris.cso.uiuc.edu all the calculators go?" -- Kryten, Red Dwarf
Re: crashes on char[]
Author: cal
Date: Thu, 17 Jan 2002 21:20
Date: Thu, 17 Jan 2002 21:20
47 lines
2218 bytes
2218 bytes
Hi there,
char asc[36864];
struct tm* localTime = new tm();
time(&timer);
localtime_r(&timer,localTime);
asctime_r(localTime, asc);
time_date = strdup(asc);
time_date[strlen(time_date) - 1] = '\0';
or
byte data[16384];
for(long offs = element.offset; offs < length; )
{
int cbRead = read(fileRead, data, 16384);
if(cbRead <= 0)
{
break;
}
offs = offs + cbRead;
write(fileWrite, data, cbRead);
}
It crashes whenever I use array....... It is ok on SUN but when I port to
HP, the problem comes out........
<John Gordon>; <217-352-6511x7418>; "CEERD-CF-N"
<gordon@osiris.cso.uiuc.edu> wrote in message
news:xKG18.7544$tg4.94829@vixen.cso.uiuc.edu...
> "cal" <ccheng@cybermation.com> writes:
>
> > Hi there,
> > My program crashes whenever I use char array, eg,
>
> > char data[1024];
>
> you're probably copying too many characters into the array.
>
> post your code, and we might be able to help you further.
>
> ---
> John Gordon "No Silicon Heaven? Preposterous! Where
would
> gordon@osiris.cso.uiuc.edu all the calculators go?" -- Kryten, Red
Dwarf
Re: crashes on char[]
Author: John Gordon217-352-6511x7418CEER...
Date: Thu, 17 Jan 2002 22:00
Date: Thu, 17 Jan 2002 22:00
35 lines
1942 bytes
1942 bytes
"cal" <ccheng@cybermation.com> writes:
> Hi there,
> char asc[36864];
> struct tm* localTime = new tm();
> time(&timer);
> localtime_r(&timer,localTime);
> asctime_r(localTime, asc);
> time_date = strdup(asc);
> time_date[strlen(time_date) - 1] = '\0';
> or
> byte data[16384];
> for(long offs = element.offset; offs < length; )
> {
> int cbRead = read(fileRead, data, 16384);
> if(cbRead <= 0)
> {
> break;
> }
> offs = offs + cbRead;
> write(fileWrite, data, cbRead);
> }
you haven't given us enough information. these code fragments *seem*
okay, but the problem could easily lie somewhere else in your program.
memory errors are very tricky.
you need to post the *entire* program.
---
John Gordon "No Silicon Heaven? Preposterous! Where would
gordon@osiris.cso.uiuc.edu all the calculators go?" -- Kryten, Red Dwarf
Re: crashes on char[]
Author: Barry Margolin
Date: Thu, 17 Jan 2002 23:09
Date: Thu, 17 Jan 2002 23:09
48 lines
2803 bytes
2803 bytes
In article <QeH18.95370$Z2.1353672@nnrp1.uunet.ca>,
cal <ccheng@cybermation.com> wrote:
>
>Hi there,
>
>char asc[36864];
>struct tm* localTime = new tm();
>time(&timer);
>localtime_r(&timer,localTime);
>asctime_r(localTime, asc);
>time_date = strdup(asc);
>time_date[strlen(time_date) - 1] = '\0';
>
>or
>
>byte data[16384];
>for(long offs = element.offset; offs < length; )
>{
> int cbRead = read(fileRead, data, 16384);
> if(cbRead <= 0)
> {
> break;
> }
> offs = offs + cbRead;
> write(fileWrite, data, cbRead);
> }
>
>It crashes whenever I use array....... It is ok on SUN but when I port to
>HP, the problem comes out........
Are those arrays global or automatic?
Your original post said that this is a multi-threaded program. If you're
using the same global array in multiple threads, and don't have a mutex to
mediate access to it, you can have problems.
Another thing is that some architectures have a limit on the size of a
stack frame, so you can't have huge automatic arrays. But I would expect
the compiler to complain if you were exceeding the limits.
Can you post a simple, complete example program (with main() and
everything) that has this problem?
--
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Re: crashes on char[]
Author: cal
Date: Fri, 18 Jan 2002 20:29
Date: Fri, 18 Jan 2002 20:29
59 lines
3175 bytes
3175 bytes
It is a large project so can really post the whole program. But it is a
multi threaded program. May be I passed a wrong options to the compiler.
I use gcc 302 with the
option -D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L then link
with -lpthread. Is the option correct? And there is no -mt on HP11..........
Thanks for the help
"Barry Margolin" <barmar@genuity.net> wrote in message
news:CQI18.21$Gk3.27088@burlma1-snr2...
> In article <QeH18.95370$Z2.1353672@nnrp1.uunet.ca>,
> cal <ccheng@cybermation.com> wrote:
> >
> >Hi there,
> >
> >char asc[36864];
> >struct tm* localTime = new tm();
> >time(&timer);
> >localtime_r(&timer,localTime);
> >asctime_r(localTime, asc);
> >time_date = strdup(asc);
> >time_date[strlen(time_date) - 1] = '\0';
> >
> >or
> >
> >byte data[16384];
> >for(long offs = element.offset; offs < length; )
> >{
> > int cbRead = read(fileRead, data, 16384);
> > if(cbRead <= 0)
> > {
> > break;
> > }
> > offs = offs + cbRead;
> > write(fileWrite, data, cbRead);
> > }
> >
> >It crashes whenever I use array....... It is ok on SUN but when I port to
> >HP, the problem comes out........
>
> Are those arrays global or automatic?
>
> Your original post said that this is a multi-threaded program. If you're
> using the same global array in multiple threads, and don't have a mutex to
> mediate access to it, you can have problems.
>
> Another thing is that some architectures have a limit on the size of a
> stack frame, so you can't have huge automatic arrays. But I would expect
> the compiler to complain if you were exceeding the limits.
>
> Can you post a simple, complete example program (with main() and
> everything) that has this problem?
>
> --
> Barry Margolin, barmar@genuity.net
> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
group.
Re: crashes on char[]
Author: Jerome Zago
Date: Fri, 18 Jan 2002 21:09
Date: Fri, 18 Jan 2002 21:09
15 lines
1767 bytes
1767 bytes
cal wrote: > It is a large project so can really post the whole program. Try to find the shortest program still showing the problem (probably less than 40 lines), unless the following paragraph solves your problem... > But it is a multi threaded program. Look at http://www.cs.cf.ac.uk/Dave/C/node30.html, section "Building Your Own Thread Stack". pthread_attr_setstacksize() could be your friend, after pthread_attr_init(), and before pthread_create(). > I use gcc 302 [...] If everything else fails, try with gcc 3.0.3, just in case ;) Hope it helps.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads