Fix "warning: enumeration value ... not handled in switch" in nsThebesDeviceContext::SetDPI()

RESOLVED FIXED

Status

()

RESOLVED FIXED
9 years ago
9 years ago

People

(Reporter: dholbert, Assigned: dholbert)

Tracking

Trunk
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [build_warning])

Attachments

(1 attachment)

(Assignee)

Description

9 years ago
Created attachment 417728 [details] [diff] [review]
fix: add default case with a NS_NOTREACHED

Bug 449283 introduced 14 lines of build warnings for nsThebesDeviceContext:
> nsThebesDeviceContext.cpp: In member function 'nsresult nsThebesDeviceContext::SetDPI()':
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeImage' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeXlib' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeXcb' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeGlitz' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeWin32' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeBeOS' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeDirectFB' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeSVG' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeOS2' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeWin32Printing' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeQuartzImage' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeQPainter' not handled in switch
> nsThebesDeviceContext.cpp:641: warning: enumeration value 'SurfaceTypeDDraw' not handled in switch

Link to source: http://mxr.mozilla.org/mozilla-central/source/gfx/src/thebes/nsThebesDeviceContext.cpp?mark=642-661#641

Simple fix: Add a "default" case.

The switch statement initializes the local variable "dpi" to something other than its default value of -1.  Based on an assertion lower down at line 689 -- NS_ASSERTION(dpi != -1, "no dpi set") -- it looks like we expect that any execution paths that hit our switch statement will fall into one of the already-provided "case" statements.  So, I think it makes sense to add a NS_NOTREACHED in the added "default" case.
Attachment #417728 - Flags: review?(mark.finkle)
(Assignee)

Comment 1

9 years ago
(In reply to comment #0)
> The switch statement initializes the local variable "dpi" to something other
> than its default value of -1.

er, s/default/initial/
Comment on attachment 417728 [details] [diff] [review]
fix: add default case with a NS_NOTREACHED

Looks good to me
Attachment #417728 - Flags: review?(mark.finkle) → review+
(Assignee)

Comment 3

9 years ago
http://hg.mozilla.org/mozilla-central/rev/42f72c150d0b
Status: NEW → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
(Assignee)

Comment 4

9 years ago
This needed a bustage fix, since the case statements in the "#ifdef XP_WIN" block declared a variable without creating a new local scope.
http://hg.mozilla.org/mozilla-central/rev/4d6088e26437
(Assignee)

Updated

9 years ago
Assignee: nobody → dholbert
(Assignee)

Updated

9 years ago
Whiteboard: [build_warning]
You need to log in before you can comment on or make changes to this bug.