SizeIt



  • Found this undocumented function in our legacy codbase:

    int SizeIt(char *inputField, char *outputField, int outputFieldBufferSize, int length)

    From the name you may, if lucky, correctly guess it copies input to output truncating or padding (wth spaces) to the specified length.

    It also converts the string to upper case and replace all instances of ; and _ with spaces. Wasn't that obvious?

    Bonus WTF: Based on some of the places it is called it looks like at some point in the distant past length was not supplied as a parameter by via a global variable.




  • @Mithious said:

    It also converts the string to upper case and replace all instances of ; and _ with spaces. Wasn't that obvious?

    You should learn not to trust your interpretation of names, or read them very carefully. If the function hadn't replaced lower to upper case, it would probably have been called sizeIt(), or dimSp20().

     



  • Also, the first parameter should be const, unless the replacement also applies to the source string (which would be a WTF in its own right).



  • @Medinoc said:

    Also, the first parameter should be const, unless the replacement also applies to the source string (which would be a WTF in its own right).
     

    Nobody uses const.

    That's because using it makes the compiler complain when your code is wrong, and nobody likes that.


Log in to reply