[Bug c++/31825] New: bug in g++ a.out for stl::map

2007-05-04 Thread lbana at hotmail dot com
# gcc -v
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: ./configure
Thread model: posix
gcc version 3.4.4


I have compiled a simple test program in C++ using stl::map. 

#g++ -DDOESNT_WORK test.cpp
#./a.out
Added value
TYpe=0name = varnum0value =199
Added value
TYpe=1name = varnum1value =200
Added value
TYpe=2name = varnum2value =201
Added value
TYpe=3name = varnum3value =202
Added value
TYpe=4name = varnum4value =203
Added value
TYpe=5name = varnum5value =204
Added value
TYpe=6name = varnum6value =205
Added value
TYpe=7name = varnum7value =206
Added value
TYpe=8name = varnum8value =207
Added value
TYpe=9name = varnum9value =208
Size = 1
Type = 0Name = varnum0value= 199

#g++ -DTHIS_WORKS test.cpp
# ./a.out
Added value
TYpe=0name = varnum0value =199
Added value
TYpe=1name = varnum1value =199
Added value
TYpe=2name = varnum2value =100
Added value
TYpe=3name = varnum3value =100
Added value
TYpe=4name = varnum4value =100
Added value
TYpe=5name = varnum5value =100
Added value
TYpe=6name = varnum6value =100
Size = 7
Type = 0Name = varnum0value= 199
Type = 1Name = varnum1value= 199
Type = 2Name = varnum2value= 100
Type = 3Name = varnum3value= 100
Type = 4Name = varnum4value= 100
Type = 5Name = varnum5value= 100
Type = 6Name = varnum6value= 100

File : test.cpp
#include "uv_type.h"

int main(const int argc, const char **argv)
{
UserVariable uv;
char name[10];
char var[20];

#if defined (DOESNT_WORK)
for (int i = 0; i < 10; i++)
{
sprintf(name, "varnum%d", i);
sprintf(var, "%d", i + 199);

uv.AddUserVar(i, name, var);
}
#endif
#if defined (THIS_WORKS)
uv.AddUserVar(0, "varnum0", "199");
uv.AddUserVar(1, "varnum1", "199");
uv.AddUserVar(2, "varnum2", "100");
uv.AddUserVar(3, "varnum3", "100");
uv.AddUserVar(4, "varnum4", "100");
uv.AddUserVar(5, "varnum5", "100");
uv.AddUserVar(6, "varnum6", "100");
#endif
uv.Print();
return 0;
}

file: uv_type.h
#ifndef UV_TYPE_H
#define UV_TYPE_H

#include 
#include 

typedef struct
{
int  type;
char name[40];
char data[80];
}
UserVar;

typedef std::mapUVTable;
typedef UVTable::value_type UVEntry;

class UserVariable
{
public:
UserVariable() {}
~UserVariable() {}
int AddUserVar(int type, char *name, char *value)
{
UserVar var;
int ret = 0;
UVTable::iterator iter;

var.type = type;
if (strlen(name) < 40)
{
strcpy(var.name, name);
}
else
{
return 1;
}

if (strlen(value) < 80)
{
strcpy(var.data, value);
}
else
{
return 1;
}

UVEntry entry(name, var);

tbl.insert(UVEntry(name, var));
std::cout << "Added value" << std::endl;
std::cout << "TYpe=" << type << "name = "<< name << "value ="
  << value << std::endl;

return 0;
}

int DelUserVar(int type, char *name)
{
}

void Print()
{
UVTable::iterator iter;

std::cout << "Size = " << tbl.size() << std::endl;

for (iter = tbl.begin(); iter != tbl.end(); iter++)
{
UserVar &var = iter->second;
std::cout << "Type = " << var.type
  << "Name = " << var.name
  << "value= " << var.data << std::endl;
}
}
protected:
UVTable tbl;
};

#endif


-- 
   Summary: bug in g++ a.out for stl::map
   Product: gcc
   Version: 3.4.4
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lbana at hotmail dot com
  GCC host triplet: Linux 2.6.19-1.2911.6.5.fc6 #1 SMP i686 i686 i386
GNU/Linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31825



[Bug libstdc++/31825] bug in g++ a.out for stl::map

2007-05-04 Thread lbana at hotmail dot com


--- Comment #3 from lbana at hotmail dot com  2007-05-05 05:01 ---
Subject: RE:  bug in g++ a.out for stl::map

Dear Gnu,
Sorry for logging invalid bug, I should have spend some time in reading it.
I thought all I need to do is pass stack variable. Anyhow thanks for the 
advice.
-Laxman
>--- Comment #2 from pcarlini at suse dot de  2007-05-05 00:11 ---
>You are only passing around a pointer to name and not allocating memory for 
>the
>various "C" strings, instead overwriting each time in the loop the same 
>char
>array. Well, there are also other problems in the code, like not passing to
>std::map as third template argument an appropriate comparison object:
>
>struct ltstr
>{
>   bool operator()(const char* s1, const char* s2) const
>   {
> return std::strcmp(s1, s2) < 0;
>   }
>};
>
>I would suggest always using std::string, instead of "C" strings, at least
>while you are still learning std::map.
>
>
>--
>
>pcarlini at suse dot de changed:
>
>What|Removed |Added
>
>  Status|UNCONFIRMED |RESOLVED
>  Resolution||INVALID
>
>
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31825
>
>--- You are receiving this mail because: ---
>You reported the bug, or are watching the reporter.

_
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31825



[Bug c/55746] New: vfprintf behaves differently variable on stack vs const argument.

2012-12-19 Thread lbana at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55746



 Bug #: 55746

   Summary: vfprintf behaves differently variable on stack vs

const argument.

Classification: Unclassified

   Product: gcc

   Version: 4.2.1

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: c

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: lb...@hotmail.com





Here is the test code that behaves differently w.r.t vfprintf. In one case it

prints the string where as in other case it crashes.



#include 

#include 

int main(int argc, const char **argv)

{

const char *var = "Test VarArg\n";



asm("nop");

asm("nop");

vfprintf(stdout, "TestMe\n", 0);

asm("nop");

asm("nop");

fflush(stdout);

asm("nop");

asm("nop");

vfprintf(stdout, var, 0);

asm("nop");

asm("nop");

fflush(stdout);



return 0;

}



#gcc -g -o t3 t3.c 

#./t3

TestMe

Segfault





In first case vfprintf is optimized with _fwrite in the second case it uses

_vfprintf and crashes probably in va_copy.



thanks in advance.

lb