Fix reversed mask usage of subbuffer offset
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 25 Aug 2011 17:49:01 +0000 (13:49 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 25 Aug 2011 17:49:01 +0000 (13:49 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/backend.h
libringbuffer/ring_buffer_backend.c

index d93f6d1fd09ef2da267ce0b0a7307202a3f9427c..83e07e426b3de3458a995bcfa953e0e33ee9d1fb 100644 (file)
@@ -88,7 +88,7 @@ void lib_ring_buffer_write(const struct lib_ring_buffer_config *config,
         */
        CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
        lib_ring_buffer_do_copy(config,
-                               shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)),
+                               shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)),
                                src, len);
        ctx->buf_offset += len;
 }
index bec31a30aeafbcfac8a9cf8fec08b27e3253a507..3e202978465ba73923a5c75645011ede0ff18954 100644 (file)
@@ -62,7 +62,7 @@ int lib_ring_buffer_backend_allocate(const struct lib_ring_buffer_config *config
        /* Allocate backend pages array elements */
        for (i = 0; i < num_subbuf_alloc; i++) {
                align_shm(shmobj, __alignof__(struct lib_ring_buffer_backend_pages));
-               set_shmp(shmp(handle, bufb->array)[i].shmp,
+               set_shmp(shmp_index(handle, bufb->array, i)->shmp,
                        zalloc_shm(shmobj,
                                sizeof(struct lib_ring_buffer_backend_pages)));
                if (!shmp(handle, shmp_index(handle, bufb->array, i)->shmp))
@@ -390,7 +390,7 @@ size_t lib_ring_buffer_read(struct lib_ring_buffer_backend *bufb, size_t offset,
        CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
        CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
                     && subbuffer_id_is_noref(config, id));
-       memcpy(dest, shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)), len);
+       memcpy(dest, shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)), len);
        return orig_len;
 }
 
@@ -426,7 +426,7 @@ int lib_ring_buffer_read_cstr(struct lib_ring_buffer_backend *bufb, size_t offse
        CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
        CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
                     && subbuffer_id_is_noref(config, id));
-       str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1));
+       str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
        string_len = strnlen(str, len);
        if (dest && len) {
                memcpy(dest, str, string_len);
@@ -460,7 +460,7 @@ void *lib_ring_buffer_read_offset_address(struct lib_ring_buffer_backend *bufb,
        rpages = shmp_index(handle, bufb->array, sb_bindex);
        CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
                     && subbuffer_id_is_noref(config, id));
-       return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1));
+       return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
 }
 
 /**
@@ -482,6 +482,7 @@ void *lib_ring_buffer_offset_address(struct lib_ring_buffer_backend *bufb,
        struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
        const struct lib_ring_buffer_config *config = chanb->config;
        unsigned long sb_bindex, id;
+       void *ret;
 
        offset &= chanb->buf_size - 1;
        sbidx = offset >> chanb->subbuf_size_order;
@@ -490,5 +491,5 @@ void *lib_ring_buffer_offset_address(struct lib_ring_buffer_backend *bufb,
        rpages = shmp_index(handle, bufb->array, sb_bindex);
        CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE
                     && subbuffer_id_is_noref(config, id));
-       return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1));
+       return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1));
 }
This page took 0.026963 seconds and 4 git commands to generate.