May 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10093



--- Comment #10 from luka8088 <luka8088@owave.net> 2013-05-16 13:07:39 PDT ---
(In reply to comment #9)
> (In reply to comment #8)
> > The original issue was:
> > 
> > auto offset = text1.length - text2.length;
> > func(offset);
> > 
> > and offset turned out to be around 4294967291
> > 
> > I was thinking, setting a uint to a negative value is kind of an overflow, should it maybe be treated the same way like array bounds and be checked by druntime (with optional disabling in production release)?
> 
> Well, that's probably something the compiler can't warn about. Not statically,
> that's for sure.
> You can use a custom type which checks for bound overflows, and fallback to
> regular int for release builds.

Yeah, I could, but should that maybe be in druntime?

Also...

void main () {
  auto a = 5 - 10u; // 4294967291u
  auto b = 5u - 10; // 4294967291u
}

Why are they both unsigned?

I will take this to the forum.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10093



--- Comment #11 from Steven Schveighoffer <schveiguy@yahoo.com> 2013-05-16 13:43:31 PDT ---
(In reply to comment #8)
> The original issue was:
> 
> auto offset = text1.length - text2.length;
> func(offset);
> 
> and offset turned out to be around 4294967291
> 
> I was thinking, setting a uint to a negative value is kind of an overflow, should it maybe be treated the same way like array bounds and be checked by druntime (with optional disabling in production release)?

No.  Just change func's parameter to an int.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 16, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10093



--- Comment #12 from luka8088 <luka8088@owave.net> 2013-05-16 13:48:38 PDT ---
(In reply to comment #11)
> (In reply to comment #8)
> > The original issue was:
> > 
> > auto offset = text1.length - text2.length;
> > func(offset);
> > 
> > and offset turned out to be around 4294967291
> > 
> > I was thinking, setting a uint to a negative value is kind of an overflow, should it maybe be treated the same way like array bounds and be checked by druntime (with optional disabling in production release)?
> 
> No.  Just change func's parameter to an int.

http://dpaste.dzfl.pl/611c13d7

Yeah, it is easy to solve when you add a writeln and see that unsigned is causing the issue. =)

Btw: http://forum.dlang.org/thread/kn3f9v$25pd$1@digitalmars.com

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10093



--- Comment #13 from Steven Schveighoffer <schveiguy@yahoo.com> 2013-05-17 08:14:33 PDT ---
(In reply to comment #12)
> http://dpaste.dzfl.pl/611c13d7

http://dpaste.dzfl.pl/cf56935d

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »