Fix CppCheck 'duplicateExpression' warning

BTW, all three cases looks similar. It would be nice to refactor it
to avoid repeating code.
Merge pull request #863 from JIghtuse/master

Fix CppCheck 'duplicateExpression' warning