chapel-lang/chapel — pull request #942 by hildeth (2014-12-01 19:00:16+00:00)
Title: Use length in string copies

This is a little cleanup task left by Sung.

I stumbled across it while trying to reduce string leaks. The main idea is to reduce redundant calls to strlen where the length of a c_string is already known or has been computed for other reasons. I also inserted slightly better error checking on the return value from snprintf(), and changed one snprintf() call to a strncpy() instead.

In addition, where possible I replaced calls to __primitve("string_copy") to direct calls to the extern string_copy routine, to position us for the eventual removal of the PRIM_STRING_COPY primitive. Where the extern call is used, it is equivalent to an assertion that the string being copied is local. There is one place where that assertion fails[ChapelIO.chpl:550], so I left the __primitive("string_copy") call in place.

Also, I replaced uses of stringMove() that really should have been string_copy() with (you guessed it) string_copy(). This allowed me to simplify stringMove, because it is no longer required to conditionally allocate memory for the result.