- GOD WARNS THRINAXODON ABOUT IMPENDING DOOM - 1 Update
- *** glibc detected *** corrupted double-linked list: - 6 Updates
- Those implicit conversions ... - 3 Updates
- Those implicit conversions ... - 3 Updates
THRINAXODON THE GREAT AND POWERFUL <peradectes@gmail.com>: Jun 07 03:15PM -0700 ======================== ======================== GOD HAS COME TO THRINAXODON, WARNING HIM THAT "THE APOCALYPSE SHALL COME IN ONE DAY, FOR IF YOU DO NOT GET READY, THE ANTI-CHRIST AKA OBAMA WILL COME AND DESTROY YOU ALL." GOD ALSO GAVE THRINAXODON SPECIFIC INSTRUCTIONS TO HAVE PEOPLE DONATE TO KENT HOVIND'S GET OUT OF PRISON FUND. THRINAXODON THEN GOT UP, RAN TO HIS COMPUTER AND CLICKED ONTO HIS NEWSREADER, AND HAS WRITTEN DOWN THIS WORTHLESS TRASH OF A POST FOR YOU TO REALIZE THAT THE APOCALYPSE WILL COME IN ONE DAY. AND BY THE WAY, HUMANS *DO* HAVE ORIGINS IN THE DEVONIAN. |
ghada glissa <ghadaglissa@gmail.com>: Jun 07 08:30AM -0700 Hi all, I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get *** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 *** Source code: void Prog:: input_transfo(uint8_t al,uint8_t ml,uint8_t* aa, uint8_t* mm, uint8_t* Pl, uint8_t* Au){ uint8_t s=0; uint8_t *ll=new uint8_t[10]; input(al,s,ll); taille1 = adjust_length(s+al,16); uint8_t *Add=new uint8_t[taille1]; memcpy(Add,ll,s); memcpy(Add+s,aa,al); memcpy(Pl,mm,ml); taille2 = adjust_length(ml,16); memcpy(Au,Add,taille1); memcpy(Au+taille1,Pl,taille2); delete ll; delete AddAuthData; } void Prog:: auth(uint8_t authlen,uint8_t al,uint8_t ml,uint8_t *n,uint8_t*a,uint8_t *ms,uint8_t *k, uint8_t *MAC){ uint8_t *Pl=new uint8_t[taille2]; uint8_t *Au=new uint8_t[taille1+taille2]; input_transfo(al,ml,a,ms,Pl,Au); delete PlainData; delete AuData; } taille1 et taille2 are two globale variables I got this error when i use the second function which uses the first function. any help please?? Best regards. |
Christian Gollwitzer <auriocus@gmx.de>: Jun 07 05:44PM +0200 Am 07.06.15 um 17:30 schrieb ghada glissa: > memcpy(Au+taille1,Pl,taille2); > delete ll; > delete AddAuthData; This is very nonidiomatic C++. I haven't bothered to find the memory error in this code, but you should consider rewriting all of it into C++ using std::vector. This will probably get rid of the memory error. For example, instead of uint8_t *ll=new uint8_t[10]; you do std::vector<uint8_t> ll(10); delete ll; is cancelled, the compiler automatically gets rid of ll for you. Instead of memcpy you either use std::copy or a for loop. etc. Christian |
red floyd <no.spam.here@its.invalid>: Jun 07 10:50AM -0700 On 6/7/2015 8:44 AM, Christian Gollwitzer wrote: > using std::vector. This will probably get rid of the memory error. For > example, instead of uint8_t *ll=new uint8_t[10]; you do > std::vector<uint8_t> ll(10); Or, since it's a fixed size, don't even bother with a vector, either use a naked array of 10 (uint8_t ll[10]), or a std:array<uint8_t,10> ll; |
Barry Schwarz <schwarzb@dqel.com>: Jun 07 10:53AM -0700 On Sun, 7 Jun 2015 08:30:09 -0700 (PDT), ghada glissa > uint8_t s=0; > uint8_t *ll=new uint8_t[10]; > input(al,s,ll); What data, if any, does this function put in ll? Does it magically change s? > taille1 = adjust_length(s+al,16); What is the value of al? What does the function do? > uint8_t *Add=new uint8_t[taille1]; > memcpy(Add,ll,s); What do you expect memcpy to do since s is 0? > memcpy(Add+s,aa,al); > memcpy(Pl,mm,ml); > taille2 = adjust_length(ml,16); What does this function do? > memcpy(Au+taille1,Pl,taille2); > delete ll; > delete AddAuthData; What is AddAuthData? Do it point to allocated memory? Where do you delete the memory allocated to Add? > } >void Prog:: auth(uint8_t authlen,uint8_t al,uint8_t ml,uint8_t *n,uint8_t*a,uint8_t *ms,uint8_t *k, uint8_t *MAC){ Parameters authlen, n, k, and MAC appear to be unused in the function? > input_transfo(al,ml,a,ms,Pl,Au); > delete PlainData; > delete AuData; What are PlainData and AuData? Do they point to allocated memory? Where do you delete the memory allocated to Pl and Au? >taille1 et taille2 are two globale variables >I got this error when i use the second function which uses the first function. >any help please?? Show us your real code, the type of each global variable, and the values of both global variables and function arguments. Tell us what the uncoded called functions do. Invest in a little horizontal white space to make your code readable. -- Remove del for email |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Jun 07 11:56AM -0600 On Sun, 7 Jun 2015 08:30:09 -0700 (PDT), ghada glissa >Hi all, >I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get >*** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 *** <snip> You're probably doing something like this: char *dest = new char[40]; memcpy(dest, src, 44); When you allocate a block of memory from the heap, the system adds some information of its own before and after your allocation; this is how it keeps track of what heap memory is in use and what's free. When you overrun the end of your allocation, you destroy some of that information; at some point, the system detects that and stops your program. valgrind might help you debug this. Louis |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jun 07 10:55PM +0100 On 07/06/2015 16:30, ghada glissa wrote: > taille1 et taille2 are two globale variables > I got this error when i use the second function which uses the first function. > any help please?? As others have suggested you should be using std::vector or std::array. For future reference you must always delete[] what you new[], i.e.: char* a = new char[42]; delete[] a; /Flibble |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 07 06:22AM You know, all those implicit conversions annoy you when they kick in unexpectedly and you only wish that that conversion had been defined »explicit«, but ... then, when you are searching for implicit conversions for example purposes, suddenly none comes to your memory? I am looking for »(in)famous« examples of implicit conversions with user-defined types of the C++ standard library. So far, I remember that 1st) a char* can be implicitly converted to a ::std::string and 2nd) a stream can be implicitly converted to a bool. It also seems to be possible to implicitly convert a double to complex<double> via constexpr complex(const T& re = T(), const T& im = T()); . Do you remember other simple or famous cases of implicit conversions of the standard library? |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 07 07:07PM >There seem to be the following cases for T: Ok, this seems to be hard, so I'll try to provide some of my ideas for possible answers. Maybe you can check whether they are correct? >case 0: T has no default constructor (line 3) struct T {}; (Or does the »automatically generated« default constructor count as a »default constructor« here?) >case 1: T has a user-provided default constructor (line 4) struct T { T(){} }; >case 2: T has a deleted default constructor (line 5) struct T{ T() = deleted; } >case 3: T has no user-provided or deleted default > constructor (line 8) and does /not/ have a > non-trivial default constructor (line B) Say, for simplification, that this is the same as a »generated« trivial default constructor. struct T {}; >case 4: T has no user-provided or deleted default > constructor (line 8) and /does/ have a > non-trivial default constructor (line B) struct T { virtual f(); }; Ok, remaining questions are: Does C++ define »user-provided default constructor«? Does »no constructor« in »case 0« refer to »no user-provided default constructor« or does it really mean no effective default constructor? (But in case the second possibility applies, it should be the same as a deleted default constructor, which is treated as a separated case 2?) |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 07 08:30PM >Does C++ define »user-provided default constructor«? And in the case of »::std::array«, 23.3.2.1 contains: // no explicit construct/copy/destroy for aggregate type . Therein, »explicit constructor« does not seem to refer to a constructor labelled with the keyword »explicit«, but rather to constructor declaration in the source code. Possibly, the same is sometimes refered to by »user-provided constructor« or just »constructor«? |
Paavo Helde <myfirstname@osa.pri.ee>: Jun 07 03:39AM -0500 ram@zedat.fu-berlin.de (Stefan Ram) wrote in news:conversions- > . Do you remember other simple or famous cases of > implicit conversions of the standard library? With the standard library my favorite goes to double-to-int conversion with ::abs(int) if one has somehow included the header for C abs(int) and forgetten to include the right headers to have the ::abs(double) overload. As C++ standard library headers may include each other in unpredictable ways, this situation can occur just by a c++ version upgrade. But I think the most unfortunate automatic conversion is converting 0 to a pointer. Not standard library, but this makes it even worse. Cheers Paavo |
Luca Risolia <luca.risolia@linux-projects.org>: Jun 07 11:49AM +0200 Il 07/06/2015 08:22, Stefan Ram ha scritto: > I am looking for »(in)famous« examples of implicit conversions > with user-defined types of the C++ standard library. > 2nd) a stream can be implicitly converted to a bool. It's explicit operator bool() const; since C++11. bool a = std::cout; // ERROR bool a{std::cout}; // OK |
"Öö Tiib" <ootiib@hot.ee>: Jun 07 05:27AM -0700 On Sunday, 7 June 2015 09:22:45 UTC+3, Stefan Ram wrote: > constexpr complex(const T& re = T(), const T& im = T()); > . Do you remember other simple or famous cases of > implicit conversions of the standard library? My first favorite is how 'false' converts to null pointer. std::string foo() { return false; } At least compilers have started to warn on that one in recent few years. Second of my favorite is how implicit conversions screw up the new (too loose) initialization. void bar() { // a is vector with one element std::vector<std::string> a{{"hello"}}; // !!! :( !!! b is vector with one undefined behavior element std::vector<std::string> b{{"hello", "there"}}; // c is vector of three elements std::vector<std::string> c{{"hello", "there", "kids"}}; } AFAIK no compiler warns here. 'b' breaks since is it now implicit literal-to-pointer-to-string conversion or literal-to-pointer-to-iterator conversion? C++ compiler resolves that ambiguity aggressively and silently and chooses latter by language rules. These are quite hard to explain it to novice. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment