[Issue 2469] ICE(cod1.c) arbitrary struct accepted as struct initializer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 22 01:07:55 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2469


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
         OS/Version|Linux                       |All


--- Comment #10 from Don <clugdbug at yahoo.com.au> 2009-09-22 01:07:54 PDT ---
The root cause is that all kinds of nonsense is allowed in struct casts.
Explicit struct casts only make sense when the source and destination are of
the same size.

Patch against DMD 2.032.

Index: cast.c
===================================================================
--- cast.c    (revision 196)
+++ cast.c    (working copy)
@@ -822,6 +822,15 @@
             return e;
         }
         }
+        // Struct casts are possible only when the sizes match
+        if (typeb->ty==Tstruct || tb->ty==Tstruct) {
+        size_t fromsize = tb->size(loc);
+        size_t tosize = typeb->size(loc);
+        if (fromsize !=tosize) {
+            error("Cannot cast from %s to %s", type->toChars(), t->toChars());
+            return this;
+        }
+        }
         e = new CastExp(loc, e, tb);
     }
     }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list