Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
There is this warning when compiling this solution:
This solution is not valid, it introduces UB into the program.
So I might be missing something but how does it return false if no conditions are true? Is that something intrinsic to c?
asprintf()
is a Linux function, not in standard C or POSIX. you must either declare it manually, or#define _GNU_SOURCE
before you#include <stdio.h>
The tests free it. It's always the case when you must return a heap allocated array / string (you cannot free it yourself: where would you? After return, the statement is not executed, before return then you would return a pointer to something not allocated anymore).
Why is the memory pointed to by r not released at the end of the function
I think if the result has all 26 letters then you'd better calloc 27 (not 26) to make room for the
\0
, otherwise ...you too!
Almost identical to mine. As well as the OB1 problem (the final string might be of 27 bytes including the null terminator), there's a second issue: overflow in
letters
.won't suffer from this.
@caelumable, temp is merely a pointer. It points into same chunk of calloced memory that
final
points at.That memory will be freed in the test code.
EDIT: My mistake, the test code doesn't free the returned memory at all. I guess the author wrote code in this way to allow solutions this return references to static variables.
This comment is hidden because it contains spoiler information about the solution
eum....may I ask when dose the temp be destroyed? and why ? the temp didn't declear in the domain of the for loop, why it destroyed after the for loop?
it doesn't matter if he use sizeof(char), as this would only consume compile time and it would become a constant.