Ad
  • Custom User Avatar

    The maximum value representable by traditional Roman numerals is 3999. The longest possible string of characters is "MMMDCCCLXXXVIII", a value of 3888, with a length of 15. Therefore you need a maximum of 16 bytes to store the longest possible encoded string.

    There's no way this code will overflow a 50 byte buffer - ironically the buffer is actually too large.
    The most egregious things here are that the arguments to calloc are flipped, and that strcat has to reiterate.

  • Custom User Avatar

    Two words; Buffer overflow.
    So many solutions suffer from this problem; allocating a buffer that should be big enough.
    Memory management in C is an important part of the solution.

  • Custom User Avatar

    See my solution :) , I tried to do the general and optimal posible.