James Livesey

@jthecoder
19 Followers
74 Following
68 Posts
Writing code to change the world · Age 21 · Software Engineering Apprentice at the BBC, working on @liveg in spare time
Websitehttps://jamesl.me
Twitterhttps://twitter.com/jthecoder
GitHubhttps://github.com/James-Livesey

Unexpectedly, the CSSWG have accepted our proposal for a new <meta name=text-scale> tag!! This will change the initial font size based on the user's text size setting.

Unfortunately it's going to become part of the boilerplate for every website you make! But will really improve a11y, I hope!

`realloc`'s signature should really be

`void realloc(void** ptr, size_t size)`

instead of

`void* realloc(void* ptr, size_t size)`

so that you *have to* pass in a pointer to your pointer, which `realloc` is then able to update. That way, you don't just accidentally discard the new pointer that was given to you as a return value.

But hey — it's not like I was the author of this memory allocator. ... Oh, yeah, I am.

C is an immensely fun programming language when your code works...

...but C is an absolute nightmare to debug, as your code will more often than not have bugs in it that you'll only realise exist months later.

(That statement applies to both bugs I've written about here. They've been hiding from me for the best part of a month or two now.)

I was very hesitant to see if I could even return a list from a procedure.

By some miracle, that also works too! And also note the local scoping of `i` in that `for` loop! 😲

Oh yeah, and the good ending is, it works now!

Still, I'm not going to change how `realloc` or `CATTO_REALLOC` works, as someone's already set out a standard for how `realloc` should be called.

But I might modify `catto_appendCharToString`'s function signature to prevent my own self from falling over this problem again.

You can see what I fixed at: https://github.com/devicefuture/catto/commit/b85adf7 and https://github.com/devicefuture/atto.js/commit/111f01e

+102 -28 lines changed total (delta +74).

Fix memory and other issues with procedures · devicefuture/catto@b85adf7

A C runtime library for the atto programming language. 😺🖥️ - Fix memory and other issues with procedures · devicefuture/catto@b85adf7

GitHub

`realloc`'s signature should really be

`void realloc(void** ptr, size_t size)`

instead of

`void* realloc(void* ptr, size_t size)`

so that you *have to* pass in a pointer to your pointer, which `realloc` is then able to update. That way, you don't just accidentally discard the new pointer that was given to you as a return value.

But hey — it's not like I was the author of this memory allocator. ... Oh, yeah, I am.

C is an immensely fun programming language when your code works...

...but C is an absolute nightmare to debug, as your code will more often than not have bugs in it that you'll only realise exist months later.

(That statement applies to both bugs I've written about here. They've been hiding from me for the best part of a month or two now.)

The solution was easy — find all instances of `catto_appendCharToString`, and prepend them with `string = `, or whatever the variable that holds the string was called for a given instance of this call.

However, I'd say I lost about an hour, or an hour and a half, on this problem.

But then, there'll be a case where the memory allocator can't increase the size of the memory you want to reallocate in-place (because there's a block of memory immediately after the block you're reallocating), so it'll move your memory to a new address and give you back the new pointer, making the old pointer invalid.

Since I was throwing that new pointer away, I was still referencing my old pointer, which now is so useless that it might as well point to a random area of memory.