@@ -146,11 +146,11 @@ void bytesToBinInt(unsigned char *vecbytes, int *vecsize, int *vecres){
146
146
temp = (int * ) calloc (8 , sizeof (int ));
147
147
148
148
for (i = 0 ;i < * vecsize ;i ++ ){
149
- byteToBinInt (vecbytes [i ], temp );
150
- for (j = 0 ;j <=7 ;j ++ ){
151
- vecres [j + idres ] = temp [j ];
152
- }
153
- idres = idres + 8 ;
149
+ byteToBinInt (vecbytes [i ], temp );
150
+ for (j = 0 ;j <=7 ;j ++ ){
151
+ vecres [j + idres ] = temp [j ];
152
+ }
153
+ idres = idres + 8 ;
154
154
}
155
155
156
156
free (temp );
@@ -186,19 +186,20 @@ void bytesToInt(unsigned char *vecbytes, int *veclength, int *nbvec, int *vecres
186
186
187
187
/* initialize result vector to 0 */
188
188
for (i = 0 ; i < * reslength ; i ++ ){
189
- vecres [i ]= 0 ;
189
+ vecres [i ]= 0 ;
190
190
}
191
191
192
192
/* build output */
193
193
for (k = 0 ;k < * nbvec ;k ++ ){ /* for all input vector */
194
- idres = 0 ;
195
- for (i = 0 ;i < * veclength ;i ++ ){ /* for one input vector */
196
- byteToBinInt (vecbytes [i + k * * veclength ], temp ); /* byte -> 8 int (0/1)*/
197
- for (j = 0 ;j <=7 ;j ++ ){ /* fill in the result*/
198
- vecres [j + idres ] += temp [j ];
199
- }
200
- idres = idres + 8 ;
201
- }
194
+ idres = 0 ;
195
+ for (i = 0 ;i < * veclength ;i ++ ){ /* for one input vector */
196
+ byteToBinInt (vecbytes [i + k * * veclength ], temp ); /* byte -> 8 int (0/1)*/
197
+ for (j = 0 ;j <=7 ;j ++ ){ /* fill in the result*/
198
+ if (j + idres >= * reslength ) break ; // do not decode padding bytes
199
+ vecres [j + idres ] += temp [j ];
200
+ }
201
+ idres = idres + 8 ;
202
+ }
202
203
}
203
204
free (temp );
204
205
} /* end bytesToInt */
@@ -214,18 +215,19 @@ void bytesToDouble(unsigned char *vecbytes, int *veclength, int *nbvec, double *
214
215
215
216
/* initialize result vector to 0 */
216
217
for (i = 0 ; i < * reslength ; i ++ ){
217
- vecres [i ]= 0.0 ;
218
+ vecres [i ]= 0.0 ;
218
219
}
219
220
220
221
for (k = 0 ;k < * nbvec ;k ++ ){ /* for all input vector */
221
- idres = 0 ;
222
- for (i = 0 ;i < * veclength ;i ++ ){ /* for one input vector */
223
- byteToBinDouble (vecbytes [i + k * * veclength ], temp ); /* byte -> 8 double (0/1)*/
224
- for (j = 0 ;j <=7 ;j ++ ){ /* fill in the result*/
225
- vecres [j + idres ] += temp [j ];
226
- }
227
- idres = idres + 8 ;
228
- }
222
+ idres = 0 ;
223
+ for (i = 0 ;i < * veclength ;i ++ ){ /* for one input vector */
224
+ byteToBinDouble (vecbytes [i + k * * veclength ], temp ); /* byte -> 8 double (0/1)*/
225
+ for (j = 0 ;j <=7 ;j ++ ){ /* fill in the result*/
226
+ if (j + idres >= * reslength ) break ; // do not decode padding bytes
227
+ vecres [j + idres ] += temp [j ];
228
+ }
229
+ idres = idres + 8 ;
230
+ }
229
231
}
230
232
free (temp );
231
233
} /* end bytesToInt */
0 commit comments