Changeset 10730


Ignore:
Timestamp:
May 17, 2011, 8:18:33 PM (8 years ago)
Author:
tbretz
Message:
Fixed a bug in bitcpy
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/ByteOrder.h

    r10703 r10730  
    8787void bitcpy(T *target, size_t ntarget, const S *source, size_t nsource, size_t ss=0, size_t ts=0)
    8888{
    89     const size_t targetsize = ss==0 ? sizeof(T) : std::min(ss, sizeof(T));
    90     const size_t sourcesize = ts==0 ? sizeof(S) : std::min(ts, sizeof(S));
     89    const size_t targetsize = ts==0 ? sizeof(T)*8 : std::min(ts, sizeof(T)*8);
     90    const size_t sourcesize = ss==0 ? sizeof(S)*8 : std::min(ss, sizeof(S)*8);
    9191
    9292    const S *const ends = source + nsource;
     
    106106        *t |= (*s>>sourcepos)<<targetpos;
    107107
    108         // If not all bits fitted into targetsize the number
    109         // of copied bits is the number of bits which fitted
    110         const int n = std::min(sourcesize-sourcepos, targetsize-targetpos);
     108        // Calculate how many bits were siuccessfully copied
     109        const int ncopy = std::min(sourcesize-sourcepos, targetsize-targetpos);
    111110
    112         targetpos += n;
    113         sourcepos += n;
     111        targetpos += ncopy;
     112        sourcepos += ncopy;
    114113
    115114        if (sourcepos>=sourcesize)
     115        {
     116            sourcepos %= sourcesize;
    116117            s++;
     118        }
    117119
    118120        if (targetpos>=targetsize)
     121        {
     122            targetpos %= targetsize;
    119123            t++;
     124        }
    120125
    121         sourcepos %= sourcesize;
    122         targetpos %= targetsize;
    123126    }
    124127}
Note: See TracChangeset for help on using the changeset viewer.