~bkerensa/ubuntu/raring/yasm/fix-for-1064341

« back to all changes in this revision

Viewing changes to libyasm/intnum.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar
  • Date: 2009-07-14 08:23:59 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090714082359-10x8mjty41gzkshs
Tags: 0.8.0-1
* New upstream release (Closes: #531047).
* Removed all tasm patches, they’ve been merged upstream.
* debian/control: set debhelper dependency to 5.0 and policy to 3.8.2.
* debian/control: mention TASM in the long description.
* debian/compat: set debhelper level to 5.
* debian/links: link tasm to ytasm and tasm.1.gz to ytasm.1.gz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * POSSIBILITY OF SUCH DAMAGE.
26
26
 */
27
27
#include "util.h"
28
 
/*@unused@*/ RCSID("$Id: intnum.c 2051 2008-04-11 09:29:58Z peter $");
 
28
/*@unused@*/ RCSID("$Id: intnum.c 2133 2008-10-07 05:59:29Z peter $");
29
29
 
30
30
#include <ctype.h>
31
31
#include <limits.h>
244
244
        case 0:
245
245
            break;
246
246
        default:
247
 
            /* >32 bit conversion */
 
247
            /* >=32 bit conversion */
248
248
            while (len) {
249
249
                BitVector_Move_Left(conv_bv, 8);
250
250
                BitVector_Chunk_Store(conv_bv, 8, 0,
251
 
                                      (unsigned long)str[--len]);
 
251
                                      ((unsigned long)str[--len]) & 0xff);
 
252
            }
 
253
            intn->val.bv = BitVector_Clone(conv_bv);
 
254
    }
 
255
 
 
256
    return intn;
 
257
}
 
258
 
 
259
yasm_intnum *
 
260
yasm_intnum_create_charconst_tasm(const char *str)
 
261
{
 
262
    yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
 
263
    size_t len = strlen(str);
 
264
    size_t i;
 
265
 
 
266
    if(len*8 > BITVECT_NATIVE_SIZE)
 
267
        yasm_error_set(YASM_ERROR_OVERFLOW,
 
268
                       N_("Character constant too large for internal format"));
 
269
 
 
270
    /* be conservative in choosing bitvect in case MSB is set */
 
271
    if (len > 3) {
 
272
        BitVector_Empty(conv_bv);
 
273
        intn->type = INTNUM_BV;
 
274
    } else {
 
275
        intn->val.l = 0;
 
276
        intn->type = INTNUM_L;
 
277
    }
 
278
 
 
279
    /* tasm uses big endian notation */
 
280
    i = 0;
 
281
    switch (len) {
 
282
        case 3:
 
283
            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
 
284
            intn->val.l <<= 8;
 
285
            /*@fallthrough@*/
 
286
        case 2:
 
287
            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
 
288
            intn->val.l <<= 8;
 
289
            /*@fallthrough@*/
 
290
        case 1:
 
291
            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
 
292
        case 0:
 
293
            break;
 
294
        default:
 
295
            /* >=32 bit conversion */
 
296
            while (i < len) {
 
297
                BitVector_Chunk_Store(conv_bv, 8, (len-i-1)*8,
 
298
                                      ((unsigned long)str[i]) & 0xff);
 
299
                i++;
252
300
            }
253
301
            intn->val.bv = BitVector_Clone(conv_bv);
254
302
    }