You should be careful to consider the effect of returning EOF on any tests you make on these values. My usual approach is to cast explicitly to the widest available type of the appropriate signedness, and used the correct conversion specification for the resulting type. Limit your strings to a suitable size earlier in the code. In some programs this is just a bug, but if the program runs with more privilege than the user than it becomes a security hole. For example, suppose that the program has read some data from the user into the buffer somevar and now wants to print it out.
Various solutions exist.
Explicitly check that the result string will fit prior to the operation. If it doesn't, don't perform the operation but instead signal an error somehow. Use snprintf instead of sprintf . The disadvantage is that you have to rely on having C99 or a C library which supports snprintf as an extension. Use strncpy instead of strcpy .