|
We like to create wrappers for most standard APIs. Mostly to make it easier to swap implementations without impacting application code.
Consider a higher level allocation concept where you
MyThing* next = allocMyThing(…);
You could have a static (or dynamic) MyThing that covers the case correctly and cleanly where the malloc(0) case crops up.
Different types will need different implementations to correctly avoid malloc(0).
IF you stick with allowing malloc(0), try some more band aids…
If running in test:
it might be best to assert and crash the program. What condition is trying to malloc(0)? Fix it.
For non-test:
It seems like your wrapper method could check for 0 size and return a (global?) static pointer to a zeroed block of memory.
You would get a safe pointer back, but like other posters have pointed out, you should never really dereference a pointer to nothing. If this is cast to char*, you would have a in effect a zero length string.
If you use a global static, the caller could check against the returned value for an exact pointer match, but again it seems it would be best to never call malloc(0).
If it is new code, avoid the malloc(0) calls.
If this legacy code, good luck!
Edit
If you use the static, your wrapper for free() will need to check for a match and skip the actual call to free().
If you wrap malloc, you need to wrap the inverse API as well!
|
|
|
|
|
All excellent advise. Some which I already follow. Thanks, appreciate it.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 549 4/6
⬛⬛⬛🟨⬛
⬛⬛🟩⬛🟨
🟩🟩🟩⬛⬛
🟩🟩🟩🟩🟩
Back to normal!
|
|
|
|
|
Wordle 549 3/6
⬜🟨🟩⬜⬜
⬜🟩🟩⬜🟩
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 4/6
⬜🟨⬜⬜⬜
⬜⬜🟩🟨⬜
🟨🟨🟩⬜⬜
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 3/6
⬜⬜🟩🟨⬜
⬜⬜🟨🟨🟨
🟩🟩🟩🟩🟩
Yay starters!
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Wordle 549 5/6
🟨⬜🟩⬜⬜
⬜⬜🟩⬜⬜
⬜🟨🟩⬜⬜
⬜🟩🟩🟩⬜
🟩🟩🟩🟩🟩
It was the only possible word with my letters and I didn't see it (looked it up)
|
|
|
|
|
Wordle 549 5/6
⬛⬛🟨⬛⬛
⬛🟨⬛⬛⬛
⬛⬛⬛⬛🟨
⬛🟨🟩⬛🟨
🟩🟩🟩🟩🟩
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Wordle 549 2/6
⬜⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Not bad started strong
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 549 3/6
⬜🟨⬜⬜⬜
🟨🟨🟨🟨⬜
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That was a very good second guess
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
The first one covered three vowels, none of which came up - so I wanted a word with at least one of the other two. Given the three that aren't there, the letter I did get in the wrong place was very unlikely to be at the start or end, so middle was the best guess. I was lucky with the four of 'em, and it only left me one choice for the third guess.
(Trying not to give spoilers, here!)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And succeeding
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
⬜🟨⬜⬜⬜
🟨🟨⬜⬜🟩
🟩🟩🟩🟩🟩
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 549 5/6*
⬜🟨⬜⬜🟨
⬜🟨🟨🟩⬜
⬜🟨🟩🟩⬜
🟩⬜🟩🟩⬜
🟩🟩🟩🟩🟩
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
Very apt...
Wordle 549 3/6*
⬜🟨⬜⬜⬜
⬜🟨🟩⬜🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 4/6
⬛🟨⬛⬛⬛
🟨⬛⬛⬛🟨
⬛🟩🟩🟩🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 5/6
⬛⬛⬛⬛⬛
⬛🟨🟩⬛⬛
⬛🟨🟩🟩⬛
⬛⬛🟩🟩🟨
🟩🟩🟩🟩🟩
Get me coffee and no one gets hurt!
|
|
|
|
|
Yep, here I go again. Working with windows for 25 years. Windows 7, 8, 10 - Xp - gasp - task bar with search at the bottom. Nah, let's change the default.
Okay, let's try dragging it around. Nope, doesn't work like Windows 7 or 10. Nah, why be consistent?
Google reveals I have to go to task bar settings - where I only have center and left selections. Microsoft claims this is a better user experience. huh
As a Christmas present to all of my listeners I am going to go purchase that task bar tool. Windows 12 will duplicate it, because what Microsoft did should have gotten a few people fired. For all of you who have criticized me for complaining or getting angry, you really cannot defend MS. If you do... well.
for the record, I'm building a new release. It would have been out earlier, but Microsoft rebooted all of my build VMs.
Ho ho ho.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: As a Christmas present to all of my listeners I am going to go purchase that task bar tool.
I assume that should be publish the task bar tool, not purchase?
Keep Calm and Carry On
|
|
|
|
|
no, there is a tool out there - Start11 - but it was supposed to do what I want but doesn't (make the W11 taskbar behave like W10).
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Devices and Printers now too.
It seems like settings might be more mobile friendly.
Aside from that I can't imagine what they are thinking day to day over there.
|
|
|
|
|
charlieg wrote: Xp - gasp - task bar with search at the bottom.
Not sure what that means but I don't think XP had a 'search' in the taskbar.
|
|
|
|
|
sorry, I was at a party.... no xp does not have a task bar search and in all fairness to MSucks the task bar approach really improved on the way to Windows 10. A user could put the task bar anywhere they wanted. Windows 11? Nope. Predictability is very important in UI, and I for one and elephanting tired of this MS crap.
I want to be clear when I say this - there is no way in holy hell that MS is doing studies and research to help users. They are screwing with stuff to cause churn and make it look new. They categorically suck.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: there is no way in holy hell that MS is doing studies and research to help users. They are screwing with stuff to cause churn and make it look new
Yes...and?
Most of the stuff in Microsoft is driven by Microsoft. There is no product that they need to catch up with or compete with. So to increase sales they must make changes and then market them as worthwhile.
Which is exactly what every other market leader does in every industry.
|
|
|
|