Author: marek
Date: 2005-03-21 04:17:15 -0500 (Mon, 21 Mar 2005)
New Revision: 42042
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/class.cs
trunk/mcs/mcs/expression.cs
Log:
2005-03-21 Marek Safar <[EMAIL PROTECTED]>
* class.cs (FixedField.Define): Check for CS1664 and more sanity
checks.
* expression.cs (ElementAccess.DoResolveLValue): Check for CS1708.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2005-03-21 08:37:32 UTC (rev 42041)
+++ trunk/mcs/mcs/ChangeLog 2005-03-21 09:17:15 UTC (rev 42042)
@@ -1,3 +1,10 @@
+2005-03-21 Marek Safar <[EMAIL PROTECTED]>
+
+ * class.cs (FixedField.Define): Check for CS1664 and more sanity
+ checks.
+
+ * expression.cs (ElementAccess.DoResolveLValue): Check for CS1708.
+
2005-03-18 Marek Safar <[EMAIL PROTECTED]>
* modifiers.cs (Modifiers.PROPERTY_CUSTOM): New constant for
Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2005-03-21 08:37:32 UTC (rev 42041)
+++ trunk/mcs/mcs/class.cs 2005-03-21 09:17:15 UTC (rev 42042)
@@ -5444,13 +5444,27 @@
return false;
}
- buffer_size = (int)c.GetValue ();
+ IntConstant buffer_size_const = c.ToInt (Location);
+ if (buffer_size_const == null)
+ return false;
+
+ buffer_size = buffer_size_const.Value;
+
if (buffer_size <= 0) {
Report.Error (1665, Location, "Fixed sized
buffer '{0}' must have a length greater than zero", GetSignatureForError ());
return false;
}
- buffer_size *= Expression.GetTypeSize (MemberType);
+ int type_size = Expression.GetTypeSize (MemberType);
+
+ if (buffer_size > int.MaxValue / type_size) {
+ Report.Error (1664, Location, "Fixed sized
buffer of length '{0}' and type '{1}' exceeded 2^31 limit",
+ buffer_size.ToString (),
TypeManager.CSharpName (MemberType));
+ return false;
+ }
+
+ buffer_size *= type_size;
+
// Define nested
string name = String.Format ("<{0}>__FixedBuffer{1}",
Name, GlobalCounter++);
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2005-03-21 08:37:32 UTC (rev 42041)
+++ trunk/mcs/mcs/expression.cs 2005-03-21 09:17:15 UTC (rev 42042)
@@ -7800,10 +7800,14 @@
if (fe != null) {
IFixedBuffer ff =
AttributeTester.GetFixedBuffer (fe.FieldInfo);
if (ff != null) {
+ if (!(fe.InstanceExpression is
LocalVariableReference) &&
+ !(fe.InstanceExpression is
This)) {
+ Error (1708, "Fixed buffers can
only be accessed through locals or fields");
+ return null;
+ }
// TODO: not sure whether it is correct
// if (!ec.InFixedInitializer) {
-// if (!ec.InFixedInitializer) {
-// Error (1666, "You cannot use
fixed sized buffers contained in unfixed expressions. Try using the fixed
statement.");
+// Error (1666, "You cannot use
fixed sized buffers contained in unfixed expressions. Try using the fixed
statement");
// return null;
// }
return MakePointerAccess (ec,
ff.ElementType);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches