Closed
Bug 1057642
Opened 11 years ago
Closed 11 years ago
PointTyped::x being CoordTyped breaks printf("%f", point.x)
Categories
(Core :: Graphics: Layers, defect)
Core
Graphics: Layers
Tracking
()
RESOLVED
FIXED
mozilla34
People
(Reporter: botond, Assigned: botond)
References
Details
Attachments
(3 files, 2 obsolete files)
5.94 KB,
patch
|
botond
:
review+
kats
:
checkin+
|
Details | Diff | Splinter Review |
11.10 KB,
patch
|
botond
:
review+
|
Details | Diff | Splinter Review |
17.66 KB,
patch
|
kats
:
review+
|
Details | Diff | Splinter Review |
Mason and I discovered an unfortunate regression caused by bug 923512:
CSSPoint p; // or any other PointTyped or IntPointTyped
...
printf_stderr("(%f, %f)\n", p.x, p.y); // Undefined behaviour!
Since PointTyped::x and PointTyped::y are now of type CoordTyped, passing them as arguments to printf silently invokes undefined behaviour (since the C++ spec says that passing any object of class type as an argument for an ellipsis parameter results in undefined behaviour).
The undefined behaviour here is not theoretical, either: Mason has seen ridiculous outputs such as (33718362177536.000000, 0.000000), which went away when using
printf_stderr("(%f, %f)\n", p.x.value, p.y.value);
instead.
Unfortunately, I don't see any way to make the first example either Just Work, or give a compiler error. (If anyone does, please let me know!)
Therefore, it's not immediately clear to me what to do about this. Generally the options that I can think of are:
(1) Provide a way to print points that doesn't involve printing
their coordinates individually, such as
printf_stderr("%s", p.ToString());
Tell people (via code comments, documentation, and a dev-platform
post) that they have to either do this, or use '.value' to unwrap
the CoordTyped objects (or use a type-safe logging mechanism
such as that in gfx/2d/Logging.h).
Fix all debugging code currently in the tree to do so.
(2) Back out the portion of the bug 923512 patch that changed
PointTyped::x and PointTyped::y to be CoordTyped, leaving
them as floats.
I would prefer (1), because (2) would go against the grain of slowly making everything strongly-typed.
If no one argues strongly for (2), I will implement (1).
Comment 1•11 years ago
|
||
This also explains the mysterious crashes I was seeing on my hamachi the other day when I enabled APZC framemetrics logging. I narrowed it down to printing float values but then I went digging in printf_stderr code before giving up :/
Assignee | ||
Comment 2•11 years ago
|
||
(In reply to Botond Ballo [:botond] from comment #0)
> Unfortunately, I don't see any way to make the first example either Just
> Work, or give a compiler error. (If anyone does, please let me know!)
Turns out there is a way to make the first example give a compiler error, at least on platforms that supports the __atrribute__(format(...)) and where we build with -Werror: by adding said attribute to printf-like functions like printf_stderr. There is a work-in-progress effort to do this in bug 965022, which I'm going to pick up.
Depends on: 965022
Comment 3•11 years ago
|
||
I don't know if this helps at all but I've been fixing some call sites as I run into them. Here's the ones I've found so far.
Assignee | ||
Comment 4•11 years ago
|
||
Comment on attachment 8479082 [details] [diff] [review]
Fix some print sites
Review of attachment 8479082 [details] [diff] [review]:
-----------------------------------------------------------------
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #3)
> I don't know if this helps at all but I've been fixing some call sites as I
> run into them. Here's the ones I've found so far.
It does - thanks! My plan was to fix them together with other misuses of printf-like functions in bug 965022, but as that's still a work in progress, I think it makes sense to not leave these known issues in the tree until bug 965022 lands.
Attachment #8479082 -
Flags: review+
Updated•11 years ago
|
Attachment #8479082 -
Flags: checkin+
Comment 5•11 years ago
|
||
Keywords: leave-open
Comment 6•11 years ago
|
||
Assignee | ||
Comment 7•11 years ago
|
||
This patch does away with the .x.value, .y.value ugliness in existing places that format points, by using operator<< / ToString() to format points instead (like we did in bug 961289, part 3b for rects, and are doing in bug 1058919 for regions and matrices).
I didn't change APZCCallbackHandler::Handle[Single|Double|Long]Tap because that needs to format the point in a specific (different) way.
Attachment #8480267 -
Flags: review?(bugmail.mozilla)
Attachment #8480267 -
Flags: review?(bgirard)
Comment 8•11 years ago
|
||
Comment on attachment 8480267 [details] [diff] [review]
Do formatting of points in one place
Review of attachment 8480267 [details] [diff] [review]:
-----------------------------------------------------------------
I feel like there must a joke somewhere about logging systems being one of the hardest things in computer science... :p
::: gfx/2d/BasePoint.h
@@ +80,5 @@
> return *static_cast<Sub*>(this);
> }
>
> + friend std::ostream& operator<<(std::ostream& stream, const Sub& aPoint) {
> + return stream << '(' << aPoint.x << ',' << aPoint.y << ')';
Can we modify gfx/2d/Logging.h to use this rather than duplicating the code?
Attachment #8480267 -
Flags: review?(bugmail.mozilla) → review+
Updated•11 years ago
|
Attachment #8480267 -
Flags: review?(bgirard) → review+
Assignee | ||
Comment 9•11 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #8)
> I feel like there must a joke somewhere about logging systems being one of
> the hardest things in computer science... :p
I'll take it under advisement for my next T-shirt :p
> ::: gfx/2d/BasePoint.h
> @@ +80,5 @@
> > return *static_cast<Sub*>(this);
> > }
> >
> > + friend std::ostream& operator<<(std::ostream& stream, const Sub& aPoint) {
> > + return stream << '(' << aPoint.x << ',' << aPoint.y << ')';
>
> Can we modify gfx/2d/Logging.h to use this rather than duplicating the code?
Definitely! Updated, carrying r+.
Attachment #8480671 -
Flags: review+
Assignee | ||
Updated•11 years ago
|
Attachment #8480267 -
Attachment is obsolete: true
Assignee | ||
Comment 10•11 years ago
|
||
Fixed a compiler error, carrying r+.
Try push: https://tbpl.mozilla.org/?tree=Try&rev=66a6416d14fa
Attachment #8480671 -
Attachment is obsolete: true
Attachment #8480690 -
Flags: review+
Assignee | ||
Updated•11 years ago
|
Attachment #8480690 -
Attachment description: bug1057642-tostring.patch → Do formatting of points in one place
Assignee | ||
Comment 11•11 years ago
|
||
Solving this issue the proper way in bug 965022 has run into some roadblocks, and I don't have the time to see that through right now.
Yet, even with the mitigating patches that have landed so far, the current situation has very high footgun-potential, so we need to do something.
Therefore, I'm going to back out the part of bug 923512 that made the type of [Int]PointTyped::[x|y] a user-defined type. The attached patch does so.
Attachment #8480736 -
Flags: review?(bugmail.mozilla)
Assignee | ||
Comment 12•11 years ago
|
||
(In reply to Botond Ballo [:botond] from comment #11)
> Therefore, I'm going to back out the part of bug 923512 that made the type
> of [Int]PointTyped::[x|y] a user-defined type. The attached patch does so.
Note: my plan is to un-revert this once bug 965022 is fixed properly (whenever that may be).
Updated•11 years ago
|
Attachment #8480736 -
Flags: review?(bugmail.mozilla) → review+
Assignee | ||
Comment 13•11 years ago
|
||
Try push for backout patch: https://tbpl.mozilla.org/?tree=Try&rev=4358caac0c74
Assignee | ||
Comment 14•11 years ago
|
||
Landed the "Do formatting of points in one place" and "Revert the type of [Int]PointTyped::[x|y] to be primitive" patches:
https://hg.mozilla.org/integration/mozilla-inbound/rev/6fac9e4a3738
https://hg.mozilla.org/integration/mozilla-inbound/rev/b54f8eca9cb9
These patches constitute a fix for this bug, so I'm removing the leave-open flag, and the dependency on bug 965022. I will file a follow-up, depending on bug 965022, for reinstating the type of [Int]PointTyped::[x|y] to be [Int]CoordTyped.
No longer depends on: 965022
Keywords: leave-open
Assignee | ||
Comment 15•11 years ago
|
||
This landed on central:
http://hg.mozilla.org/mozilla-central/rev/6fac9e4a3738
http://hg.mozilla.org/mozilla-central/rev/b54f8eca9cb9
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
Assignee | ||
Comment 16•11 years ago
|
||
(In reply to Botond Ballo [:botond] from comment #14)
> These patches constitute a fix for this bug, so I'm removing the leave-open
> flag, and the dependency on bug 965022. I will file a follow-up, depending
> on bug 965022, for reinstating the type of [Int]PointTyped::[x|y] to be
> [Int]CoordTyped.
Filed bug 1060421 as a follow-up.
You need to log in
before you can comment on or make changes to this bug.
Description
•