Fix CppCheck 'duplicateExpression' warning

BTW, all three cases looks similar. It would be nice to refactor it
to avoid repeating code.