From 056ebaf148816de50b353db476b695758e5673d2 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 16 Oct 2013 18:00:02 -0400 Subject: [PATCH] ctf: Clamp float and integer declaration alignments to 1 Alignments < 1 don't make much sense, so make sure the stored value is always at least 1. StructDeclaration was doing this check, but Integer and FloatDeclaration were not. Change-Id: Iedb42a6fdda8706b7e8f522df10f67f2145bbba2 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/17434 Tested-by: Hudson CI IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam Reviewed-by: Matthew Khouzam --- .../tests/types/FloatDeclarationTest.java | 4 ++-- .../core/event/types/FloatDeclaration.java | 17 ++++++++----- .../core/event/types/IntegerDeclaration.java | 24 ++++++++++++------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java index c2950cb198..d9eb1cf8b2 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java @@ -35,8 +35,8 @@ public class FloatDeclarationTest { @Test public void getterTest() { - fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); - assertEquals( fixture.getAlignment(), 0); + fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 1); + assertEquals( fixture.getAlignment(), 1); assertEquals( fixture.getByteOrder(), ByteOrder.nativeOrder()); assertEquals( fixture.getExponent(), 8); assertEquals( fixture.getMantissa(), 24); diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java index 51f5903e9a..71ec3208d6 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java @@ -15,7 +15,7 @@ import java.nio.ByteOrder; /** * A CTF float declaration. - * + * * The declaration of a floating point basic data type. * * @version 1.0 @@ -38,17 +38,22 @@ public class FloatDeclaration implements IDeclaration { /** * Constructor - * @param exponent the exponent size in bits - * @param mantissa the mantissa size in bits (+1 for sign) (see ctf spec) - * @param byteOrder the byte order - * @param alignment the alignment + * + * @param exponent + * The exponent size in bits + * @param mantissa + * The mantissa size in bits (+1 for sign) (see CTF spec) + * @param byteOrder + * The byte order + * @param alignment + * The alignment. Should be >= 1 */ public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder, long alignment) { mant = mantissa; exp = exponent; this.byteOrder = byteOrder; - this.alignment = alignment; + this.alignment = Math.max(alignment, 1); } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java index d1de809d0f..0f7673d6e5 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java @@ -46,13 +46,21 @@ public class IntegerDeclaration implements IDeclaration { /** * Contructor - * @param len the length in bits - * @param signed is the integer signed? false == unsigned - * @param base the base (10-16 are most common) - * @param byteOrder Big endian little endian or other - * @param encoding ascii, utf8 or none. - * @param clock the clock path, can be null - * @param alignment the minimum alignment + * + * @param len + * The length in bits + * @param signed + * Is the integer signed? false == unsigned + * @param base + * The base (10-16 are most common) + * @param byteOrder + * Big endian little endian or other + * @param encoding + * ascii, utf8 or none. + * @param clock + * The clock path, can be null + * @param alignment + * The minimum alignment. Should be >= 1 */ public IntegerDeclaration(int len, boolean signed, int base, ByteOrder byteOrder, Encoding encoding, String clock, long alignment) { @@ -65,7 +73,7 @@ public class IntegerDeclaration implements IDeclaration { this.byteOrder = byteOrder; this.encoding = encoding; this.clock = clock; - this.alignment = alignment; + this.alignment = Math.max(alignment, 1); } // ------------------------------------------------------------------------ -- 2.34.1