473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Assert vector program terminates

Following is part of my program that I am trying to code to simluate
folder information which contains mp3 files.
At the end of main funcion there is assert, I have tried to debug the
program , what I found is resize() call was successful, but when main
terminates there is an assert in the vectors destructor.
#include <iostream>
#include <string>
#include <vector>

typedef int tU32;
typedef bool tBool;
typedef short tU8;
typedef void tVoid;
typedef char * tcString;
#define NULL 0

using namespace std;

enum tenFileType {
FI_EN_FOLDER = 0UL,
FI_EN_FILE = 1UL,
FI_EN_PLAYLIST = 2UL
};

enum tenGenre {
FI_EN_ROOT = 0UL,
FI_EN_PLAYLIST_1 = 1UL,
FI_EN_ARTIST = 2UL,
FI_EN_ALBUM = 3UL,
FI_EN_GENRE = 4UL,
FI_EN_TRACK = 5UL,
FI_EN_COMPOSER = 6UL,
FI_EN_AUDIOBOOK = 7UL,
FI_EN_PODCAST = 8UL,
FI_EN_UNKNOWNACTIVE = 9UL
};


enum FileAttributes
{
FILETYPE_FOLDER,
FILETYPE_FILE,
FILETYPE_ARTIST,
FILETYPE_ALBUM
};
struct trFolder{
tU32 u32Id;
tcString name;

};

struct trTime{
tU8 u8NoOfHrs;
tU8 u8NoOfMin;
tU8 u8NofSec;
};

struct trId3Data
{
tenFileType m_enFileType;
tenGenre m_enGenre;
char * m_szArtistName;
char * m_szFileName;
trTime m_trPlayTime;

trId3Data( )
{
m_szArtistName = NULL;
m_szFileName = NULL;
}

~trId3Data( )
{
if( m_szArtistName != NULL )
delete m_szArtistName;

if( m_szFileName!= NULL )
delete m_szFileName;
}

trId3Data( const trId3Data& rftrId3Data)
{
}

trId3Data(trId3Data& rftrId3Data)
{
m_enFileType = rftrId3Data.m_enFileType;
m_enGenre = rftrId3Data.m_enGenre;
vCopyStirng( m_szArtistName, rftrId3Data.m_szArtistName);
vCopyStirng( m_szFileName, rftrId3Data.m_szFileName );
m_trPlayTime.u8NoOfHrs = rftrId3Data.m_trPlayTime.u8NoOfHrs;
m_trPlayTime.u8NoOfMin = rftrId3Data.m_trPlayTime.u8NoOfMin;
m_trPlayTime.u8NofSec = rftrId3Data.m_trPlayTime.u8NofSec;
}

tVoid vCopyStirng( char *&dest , char *&src )
{
dest = (char*)malloc(strlen(src));
strcpy( dest, src );
}

tVoid vsetFileType( tenFileType enFileType )
{
m_enFileType = enFileType;
}

tVoid vsetGenre( tenGenre enGenre )
{
m_enGenre = enGenre;
}

tVoid vsetArtistName( char* ArtistName )
{
vCopyStirng( m_szArtistName, ArtistName );
}

tVoid vsetFilename(char * fileName)
{
vCopyStirng( m_szFileName, fileName );
}

tVoid vsetPlayTime( trTime &trPlayTime)
{
m_trPlayTime.u8NofSec = trPlayTime.u8NofSec;
m_trPlayTime.u8NoOfMin = trPlayTime.u8NoOfMin;
m_trPlayTime.u8NoOfHrs = trPlayTime.u8NoOfHrs;
}
};

/*!
* \fn trFolderInfo
* \brief
* Represents Basic structure of a folder
* \note
* \bug
* no bugs known
* \todo
* -Review
* \version
* 1.0 - Initial
******/
struct trFolderInfo
{
tU32 u32Id;
char* name;
struct trFolderInfo *parentdir;
std::vector<trId3DatafileList;
std::vector<trFolderInfosubdir;

trFolderInfo()
{
name = NULL;
}

~trFolderInfo()
{
if( name != NULL )
delete name;
}

tVoid vCopyStirng( char *&dest , char *&src )
{
dest = (char*)malloc(strlen(src));
strcpy( dest, src );
}

tVoid vsetFolderName(char * FolderName)
{
vCopyStirng( name, FolderName );
}

} ;

void main()
{
vector<trId3DatafileList;
fileList.resize(10);
}

Oct 6 '07 #1
7 1585
"Alf P. Steinbach" <al***@start.nowrites:
* hyderabadblues:
>typedef int tU32;
typedef bool tBool;
typedef short tU8;
typedef void tVoid;

It's not a good idea to obscure code by using names such as tVoid
instead of standard void.
It's really weird to use short as the type for tU8, since we
know that short has more than 8 bits.
--
"While the Melissa license is a bit unclear, Melissa aggressively
encourages free distribution of its source code."
--Kevin Dalley <ke***@seti.org>
Oct 6 '07 #2
On 2007-10-06 16:58, hyderabadblues wrote:
Following is part of my program that I am trying to code to simluate
folder information which contains mp3 files.
At the end of main funcion there is assert, I have tried to debug the
program , what I found is resize() call was successful, but when main
terminates there is an assert in the vectors destructor.

Using a debugger you would notice that the problem occurs when you try
to delete m_szArtistName in ~trId3Data().
tVoid vCopyStirng( char *&dest , char *&src )
{
dest = (char*)malloc(strlen(src));
^^^^^^^
strcpy( dest, src );
}
tVoid vCopyStirng( char *&dest , char *&src )
{
dest = (char*)malloc(strlen(src));
^^^^^^
strcpy( dest, src );
}
Memory allocated with malloc must be deallocated with free, (likewise,
memory allocated with new must be deallocated with delete). In C++
programs new should be used unless you need to allocate memory
deallocated by libraries written in C (which is bad design, so you
probably should not use such libraries any way).

--
Erik Wikström
Oct 6 '07 #3
On 2007-10-06 17:59, Ben Pfaff wrote:
"Alf P. Steinbach" <al***@start.nowrites:
>* hyderabadblues:
>>typedef int tU32;
typedef bool tBool;
typedef short tU8;
typedef void tVoid;

It's not a good idea to obscure code by using names such as tVoid
instead of standard void.

It's really weird to use short as the type for tU8, since we
know that short has more than 8 bits.
Actually, on a 7-bit machine a short could be 7 bits as well. All we
know is that short has at least as many bits as a signed char.

--
Erik Wikström
Oct 6 '07 #4
On Oct 6, 5:59 pm, Ben Pfaff <b...@cs.stanford.eduwrote:
"Alf P. Steinbach" <al...@start.nowrites:
* hyderabadblues:
typedef int tU32;
typedef bool tBool;
typedef short tU8;
typedef void tVoid;
It's not a good idea to obscure code by using names such as tVoid
instead of standard void.

It's really weird to use short as the type for tU8, since we
know that short has more than 8 bits.
--
"While the Melissa license is a bit unclear, Melissa aggressively
encourages free distribution of its source code."
--Kevin Dalley <ke...@seti.org>
I am working for a embedded systems company, so to try out something I
use visual studio, above defines are just mine for trials.

Oct 6 '07 #5
In article <Cq*****************@newsb.telia.net>, Erik-
wi******@telia.com says...

[ ... ]
Actually, on a 7-bit machine a short could be 7 bits as well. All we
know is that short has at least as many bits as a signed char.
A signed char must support a range from at least -127 to +127. A short
must support a range from at least -32767 to +32767. Each signed type
must also occupy the same amount of storage as its corresponding
unsigned type, and an unsigned char must support a range from at least 0
through 255. An unsigned short must support a ranage from at least 0
through 65535.

IOW, in C or C++ a char or unsigned char must occupy least 8 bits, and a
short or unsigned short must occupy at least 16 bits.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Oct 6 '07 #6
On 2007-10-06 18:27, Jerry Coffin wrote:
In article <Cq*****************@newsb.telia.net>, Erik-
wi******@telia.com says...

[ ... ]
>Actually, on a 7-bit machine a short could be 7 bits as well. All we
know is that short has at least as many bits as a signed char.

A signed char must support a range from at least -127 to +127. A short
must support a range from at least -32767 to +32767. Each signed type
must also occupy the same amount of storage as its corresponding
unsigned type, and an unsigned char must support a range from at least 0
through 255. An unsigned short must support a ranage from at least 0
through 65535.

IOW, in C or C++ a char or unsigned char must occupy least 8 bits, and a
short or unsigned short must occupy at least 16 bits.
I forgot about good old C. This makes me wonder however, why is no
reference made to the relevant sections of the C standard when
discussing the integer types instead of hiding that away down in section
18.2.2?

--
Erik Wikström
Oct 6 '07 #7
In article <5v*****************@newsb.telia.net>, Erik-
wi******@telia.com says...

[ ... ]
I forgot about good old C. This makes me wonder however, why is no
reference made to the relevant sections of the C standard when
discussing the integer types instead of hiding that away down in section
18.2.2?
There is, at least indirectly -- in 3.9.1 footnote 39 mentions that
int's most be "large enough to contain any value in the range INT_MIN
and INT_MAX as defined in the header <climits>"

That's about it though, and an extremely minimal reference (at best) it
is too...

--
Later,
Jerry.

The universe is a figment of its own imagination.
Oct 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
24
by: simon | last post by:
Hi, First some background. I have a structure, struct sFileData { char*sSomeString1; char*sSomeString2;
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
21
by: Giuseppe | last post by:
is assert() for debug only or not? Is it possible that I have seen the use of assert() in the Borland c++ 32 compiler (so assert is not for debug only)?
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
47
by: Rob Thorpe | last post by:
In general, is it considered bad practice to use asserts in production code? What about writing a macro that does the same as assert but continues to work regardless of the state of NDEBUG? I...
28
by: lovecreatesbeauty | last post by:
Besides printing out for example " a.out: p113.c:8: main: Assertion `0' failed. Aborted " and a switch option NDEBUG, what other benefits does assert() provide in any scope of designing,...
1
by: ngaloppo | last post by:
Hi, I sometimes convert std::vector::iterators to pointers by the (afaik) legal construct &v, e.g. in the construct below. In debug build, the program terminates, because of what seems to be...
32
by: bingfeng | last post by:
hello, please see following two code snatches: 1. int foo (const char* some) { assert(some); if (!some) { return -1; //-1 indicates error }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.