6 kyu

Networking 101/4: Determine the IPv4 network prefix in CIDR notation

54 of 139bitcanon
Description
Loading description...
Networks
Bits
Fundamentals
Binary
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Great kata and series to learn something new on computer programming.

  • jasonwa Avatar

    Thanks Donald, it was an issue that I failed to spot, I have taken another look at it and found it.

  • jasonwa Avatar

    This kata is timing out on simple sscanf/sprintf solutions which for this rank should be sufficient or are further optimisation needed?

    • donaldsebleung Avatar

      This Kata has no performance requirements as far as I'm concerned so probably an issue in your solution, such as an infinite loop. Re-raise this as a Question (the "Issue" tag is reserved for confirmed issues with the Kata itself), post your current solution as a spoiler and we can take a look.

      Issue marked resolved by donaldsebleung 3 years ago
  • donaldsebleung Avatar

    https://docs.codewars.com/languages/c/authoring/memory-management-techniques/#mixed-approach-malloc-in-the-solution-and-free-in-tests

    Performing heap memory allocation in the user solution and freeing the memory in tests is an anti-pattern that should be avoided at all costs. Please change the semantics of the user solution to either:

    • (Recommended) Receive as an extra argument a (pre-allocated) writable character buffer large enough to hold the result; or
    • (Not recommended) Keep the current semantics of the user solution, but require the user to implement their own function to free the allocated memory; however, this (testing proper memory management by the solver) is difficult, if not impossible to test explicitly on Codewars

    A recommended function signature:

    void network_cidr(const char *ipv4_addr, const char *netmask, char *result);
    

    Alternatively, return the output buffer result as well but this needs to be explicitly tested and documented:

    char *network_cidr(const char *ipv4_addr, const char *netmask, char *result);
    
    • bitcanon Avatar

      Thanks for you input, I have changed the source code as well as the description to use the void approach instead.

      Issue marked resolved by bitcanon 3 years ago