Fix index out of bounds with rtrim().

Change-Id: I8c420a45aacdb0ce8f6a83fa8cdf5e91b8ef1f77
Reviewed-on: http://gerrit.ent.cloudera.com:8080/3268
Reviewed-by: Nong Li <nong@cloudera.com>
Tested-by: jenkins