September 09, 2023
On Sat, Sep 09, 2023 at 09:21:32AM +0000, rempas via Digitalmars-d-learn wrote:
> On Saturday, 9 September 2023 at 08:54:14 UTC, Brad Roberts wrote:
> > I'm pretty sure this is your problem.  You're allocating size bytes
> > which is only going to work where sizeof(T) == 1.  Changing to
> > malloc(size * sizeof(T)) is likely going to work better.
> 
> Oh man!!!! That was it! I had forget about that! Funny enough, the reallocation tests I do letter when expanding the vector do include that but I had forgot to place it in the new (because I had the an old one and it included this) constructor I had made that only allocates memory!
> 
> Now, if only one could expect how and why "libc" knows that and doesn't just care to give me the memory I asked it for? Or it could be than D does something additional without telling us? Which can explain when this memory is only present when I assign the value to the "this._ptr` field!

libc doesn't know what you intended. All it knows is that you asked it for 20 bytes (even though you actually needed 40), then later on its internal structures are corrupted (because you thought you got 40 bytes; storing data past the 20 bytes overwrote some of malloc's internal data -- this is the buffer overrun / buffer overflow I referred to). So it aborts the program instead of continuing to run in a compromised state.


T

-- 
There are four kinds of lies: lies, damn lies, and statistics.
September 09, 2023

On Saturday, 9 September 2023 at 09:47:14 UTC, Steven Schveighoffer wrote:

>

You are focusing on the wrong problem.

You asked for size bytes, and malloc gave you size bytes. It doesn't "know" anything special.

Then you proceeded at some point to write past the size bytes. What did you overwrite? Probably some internal malloc implementation structure. Then it later noticed "hey, this structure doesn't make sense, I'm going to report it to the user!" That's why you see the message.

Memory problems are very difficult to find, and typically an error is triggered far away from the source, in seemingly unrelated code. This is why whenever I see an error that smells like memory corruption, I stop all other work and find it. Memory errors can come and go based on random chance or how the compiler lays out functions. So having it "just go away" isn't enough. Very very infrequently, this happens because of a codegen issue, but most of the time it's pilot error.

-Steve

I understand! Thank you for the valuable information. I do have lots of things to learn it seems. But that means that I also won't get bored anytime soon ;)

September 09, 2023
On Saturday, 9 September 2023 at 09:56:59 UTC, H. S. Teoh wrote:
> libc doesn't know what you intended. All it knows is that you asked it for 20 bytes (even though you actually needed 40), then later on its internal structures are corrupted (because you thought you got 40 bytes; storing data past the 20 bytes overwrote some of malloc's internal data -- this is the buffer overrun / buffer overflow I referred to). So it aborts the program instead of continuing to run in a compromised state.
>
>
> T

Thank you! I fully realize now what's the problem! And that was indeed a very sneaky problem. The good news is that I'm mostly done with these memory structures and functions so I will probably take a while since I find something similar.

I'm lucky there are people smarter, more experience that are willing to help. Bless you all and have a great day!
September 09, 2023

On Saturday, 9 September 2023 at 09:30:10 UTC, rempas wrote:

>

Bingo! You and Brad found out!

Hate to be that guy, but I posted a link to a stackoverflow question with the exact error message you were getting, and the solution. And I told you I had experienced the same error and that question fixed it.

September 09, 2023

On Saturday, 9 September 2023 at 10:54:34 UTC, bachmeier wrote:

>

Hate to be that guy, but I posted a link to a stackoverflow question with the exact error message you were getting, and the solution. And I told you I had experienced the same error and that question fixed it.

No reason to not says something, always speak you mind my friend!

I did read it and all the replies but the problem is that, I was so focused on thinking that something is going wrong with the compiler or with libc or something unexpected. For that reason, I made the mistake to not see other things that might had gotten wrong even tho you literally gave me the answer! That's another problem of mine that I am aware and trying to fix (not only when it comes to coding but in general) and I do apologize for wasting both mine and everyone else's time!

Now that people explained to me, I fully understood what's going on and how I made the mistake. Have a great day my friend and I hope I can repay one day! ;)

September 10, 2023
On Friday, 8 September 2023 at 13:34:42 UTC, Richard (Rikki) Andrew Cattermole wrote:
> In case you didn't know, all you need to get unittests working in -betterC is:
>
> ```d
> 			foreach (module_; allModules) {
> 				foreach (unitTest; __traits(getUnitTests, module_)) {
> 					unitTest();
> 				}
> 			}
> ```
>
> You'd need to provide allModules somehow, like dub does.
>
> https://github.com/dlang/dub/blob/2ea883833adf085095b07a7dba8250fb3db79a71/source/dub/project.d#L1937

TIL, thanks for sharing, this will be very useful!
1 2 3 4
Next ›   Last »