Ah yeah it should clamp. Maybe like so:

    if (g_Config.iTexScalingLevel == 0)
        scaleFactor = std::min(5, g_Config.iInternalResolution);
    else
        scaleFactor = g_Config.iTexScalingLevel;