     int warpidx = threadIdx.x >> 5;
     int tid = threadIdx.x & 31;
 
-    __shared__ uint4 s_out_all[64 * WARPS_NUM];
-    unsigned int * s_out = (unsigned int*)(s_out_all + warpidx * 64);
+    __shared__ uint4 s_out_all[(64 + 1) * WARPS_NUM];
+    unsigned int * s_out = (unsigned int*)(s_out_all + warpidx * (64 + 1));
     
     // Number of remaining codewords in shared buffer
     int remaining_codewords = 0;

        return;
    struct gpujpeg_segment* segment = &d_segment[segment_index];
    
    // Initialize huffman coder
    int dc[GPUJPEG_MAX_COMPONENT_COUNT];
    for ( int comp = 0; comp < GPUJPEG_MAX_COMPONENT_COUNT; comp++ )
        dc[comp] = 0;
    
    // Prepare data pointers
    unsigned int * data_compressed = (unsigned int*)(d_data_compressed + segment->data_temp_index);

        const uint64_t packed_block_info = *(packed_block_info_ptr++);
        
        // Get coder parameters
        const int last_dc_idx = 256 + (packed_block_info & 0x7f);
        
        // Get huffman tables
        struct gpujpeg_table_huffman_encoder* d_table_dc = NULL;
