[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: segmentation fault with g++
From: |
Mumit Khan |
Subject: |
Re: segmentation fault with g++ |
Date: |
21 Feb 2001 17:32:32 GMT |
In article <address@hidden>,
Admir Efendic <address@hidden> wrote:
>Hi!
>
>Following code works fine on Win2000 compiled with Borland C++ Builder 4.0
>Pro.
>On my linux machine it causes segmentation fault.
Use a debugger, that's what it's for!
>class LG_URLParser
>{
>private:
> char* m_url;
[...]
>LG_URLParser::LG_URLParser(const char* url)
>{
> m_url = new char(256);
^^^^^ don't you mean
new char[256];
That is, you should be allocating a buffer that can hold 256 characters,
not allocate a character and initialize it to 256!
Please learn to use std::string. Assumption such as that an URL cannot be
longer than 255 characters will eventually cause you trouble.
Regards,
Mumit