• Custom User Avatar

    It's because of integer overflow.

  • Custom User Avatar

    everything was much easier than I thought at first

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Thank you very much

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    You are indeed correct. Thanks for pointing this out!

  • Custom User Avatar

    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.

  • Custom User Avatar

    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("").

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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.

    To fix, change the line to

    return strdup("");
    
  • Custom User Avatar

    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.

    To fix, change the line to

    return strdup("");
    
  • Custom User Avatar

    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

    out[0] = 0
    
  • Custom User Avatar

    This function returns a pointer to data on the stack (char maxStr[200]), which is undefined behaviour.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...