Ignore:
Timestamp:
02/27/12 23:37:54 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
rebase_source:
84919af56633e6f084f5ed8b4b715cff35455e24
Message:

Using memcpy to write data to buffer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/slist.hpp

    r6531 r10390  
    103103  { 
    104104    ensure(sizeof(unsigned short)); 
    105     (unsigned short &)*bufptr = c; 
     105    memcpy((void *) bufptr, (void *) &c, sizeof(unsigned short)); 
    106106    bufptr += sizeof(unsigned short); 
    107107  } 
     
    110110  { 
    111111    ensure(sizeof(int)); 
    112     (int &)*bufptr = c; 
     112    memcpy((void *) bufptr, (void *) &c, sizeof(int)); 
    113113    bufptr += sizeof(int); 
    114114  } 
     
    117117  { 
    118118    ensure(sizeof(long)); 
    119     (long &)*bufptr = c; 
     119    memcpy((void *) bufptr, (void *) &c, sizeof(long)); 
    120120    bufptr += sizeof(long); 
    121121  } 
     
    124124  { 
    125125    ensure(sizeof(float)); 
    126     (float &)*bufptr = c; 
     126    memcpy((void *) bufptr, (void *) &c, sizeof(float)); 
    127127    bufptr += sizeof(float); 
    128128  } 
     
    131131  { 
    132132    ensure(sizeof(double)); 
    133     (double &)*bufptr = c; 
     133    memcpy((void *) bufptr, (void *) &c, sizeof(float)); 
    134134    bufptr += sizeof(double); 
    135135  } 
     
    140140    ensure((size + 1) * sizeof(int)); 
    141141 
    142     int *&buff = (int *&)bufptr; 
    143     *buff++ = size; 
    144     for(vector<int>::const_iterator vi = v.begin(); size--; *buff++ = *vi++); 
     142    memcpy((void *) bufptr, (void *)&size, sizeof(int)); 
     143    bufptr += sizeof(int); 
     144    if (size > 0) 
     145    { 
     146        // This is legal as &v[0] is guaranteed to point to a 
     147        // contiguous memory block 
     148        memcpy((void *) bufptr, (void *) &v[0], size * sizeof(int)); 
     149        bufptr += sizeof(int) * size; 
     150    } 
    145151  } 
    146152 
     
    150156    ensure(sizeof(int) + size * sizeof(float)); 
    151157 
    152     (int &)*bufptr = size; 
    153     bufptr += sizeof(int); 
    154  
    155     float *&buff = (float *&)bufptr; 
    156     for(vector<float>::const_iterator vi = v.begin(); size--; *buff++ = *vi++); 
    157   } 
    158  
     158    memcpy((void *) bufptr, (void *)&size, sizeof(int)); 
     159    bufptr += sizeof(int); 
     160    if (size > 0) 
     161    { 
     162        // This is legal as &v[0] is guaranteed to point to a 
     163        // contiguous memory block 
     164        memcpy((void *) bufptr, (void *) &v[0], size * sizeof(float)); 
     165        bufptr += sizeof(float) * size; 
     166    } 
     167  } 
    159168 
    160169  inline void writeBuf(const void *abuf, size_t size) 
     
    165174  } 
    166175 
    167  
    168176  inline char readChar() 
    169177  {  
Note: See TracChangeset for help on using the changeset viewer.