Fix Coverity issue 1212320

Coverity was correctly complaining about the primitive PRIM_FIELD_NUM_TO_NAME.
If the field number specified exceeded the number of fields in the record or
class, then the compiler would not modify the variable name before using it,
causing a dereference of null.  I have added a test for this case and an error
message to the user should this occur in their code.

@mppf or @bradcray would be best to review this change, since Brad merged it in back in 2011 but it was mppf's code.