Detect memory overflow and underflow