2/7/2019
To anyone trying to solve this kata, the comments above are what you need.
Essentially use "compound interest on a daily basis, with the artificial daily rate p/360".
This would have been a good kata if this had been adequately explained.
The only way to make the test cases work is to consider compound interest on a daily basis, with the artificial daily rate p/360. No bank works like this in practice, so this kata needs A LOT more description.
You are right but if I change the tests now, it will invalidate allmost all C passed solution and I think it will be bad... I will change only the reference solution.
The point is that without special knowledge about the runtime it's impossible for the caller to know whether a returned pointer is on the heap. So the contract of longestConsec must specify that any returned pointer is dynamically allocated. In order to satisfy its contract, longestConsec must therefore contain the code you posted above which is equivalent to strdup("").
This solution has a bug: ordinarily, it returns a char * allocated using malloc. However, in case the precondition isn't satisfied, it retuns a pointer to a static string "". The caller must call free on the returned pointer which will lead to heap corruption when the static string is returned.
This solution has a bug: ordinarily, it returns a char * allocated using malloc. However, in case the precondition isn't satisfied, it retuns a pointer to a static string "". The caller must call free on the returned pointer which will lead to heap corruption when the static string is returned.
In the case where the preconditions aren't satisfied, this solution allocates space for a single char and then proceeds to set the second element, out[1] = 0, leading to undefined behaviour.
It's because of integer overflow.
everything was much easier than I thought at first
This comment is hidden because it contains spoiler information about the solution
Thank you very much
2/7/2019
To anyone trying to solve this kata, the comments above are what you need.
Essentially use "compound interest on a daily basis, with the artificial daily rate p/360".
This would have been a good kata if this had been adequately explained.
The only way to make the test cases work is to consider compound interest on a daily basis, with the artificial daily rate p/360. No bank works like this in practice, so this kata needs A LOT more description.
You are indeed correct. Thanks for pointing this out!
You are right but if I change the tests now, it will invalidate allmost all C passed solution and I think it will be bad... I will change only the reference solution.
The point is that without special knowledge about the runtime it's impossible for the caller to know whether a returned pointer is on the heap. So the contract of
longestConsec
must specify that any returned pointer is dynamically allocated. In order to satisfy its contract,longestConsec
must therefore contain the code you posted above which is equivalent tostrdup("")
.This comment is hidden because it contains spoiler information about the solution
This solution has a bug: ordinarily, it returns a
char *
allocated usingmalloc
. However, in case the precondition isn't satisfied, it retuns a pointer to a static string""
. The caller must callfree
on the returned pointer which will lead to heap corruption when the static string is returned.To fix, change the line to
This solution has a bug: ordinarily, it returns a
char *
allocated usingmalloc
. However, in case the precondition isn't satisfied, it retuns a pointer to a static string""
. The caller must callfree
on the returned pointer which will lead to heap corruption when the static string is returned.To fix, change the line to
In the case where the preconditions aren't satisfied, this solution allocates space for a single
char
and then proceeds to set the second element,out[1] = 0
, leading to undefined behaviour.To fix, change the line to
This function returns a pointer to data on the stack (
char maxStr[200]
), which is undefined behaviour.This comment is hidden because it contains spoiler information about the solution
Loading more items...