Exemplo n.º 1
0
int quicksort(void *array, int dim, int pivot) {
    int *indexes, i, diff;

    indexes = (int*)malloc(dim*sizeof(int));
    if (indexes == NULL) return -ENOMEM;

    diff = dim - pivot;
    for (i = 0 ; i < dim ; i++) {
        if (i < pivot)
            indexes[i] = diff + i;
        else indexes[i] = i - pivot;
    }
#ifdef __DEBUG_QS__
    printf("Sort an array of %d items from pivot %d containing:\n", dim, pivot);
    dump_char_array((char**)array, dim);
    printf("Unsorted indexes: ");
    dump_int_array(indexes, dim);
#endif
    __quicksort(array, indexes, 0, dim-1);

#ifdef __DEBUG_QS__
    printf("Sorted into:\n");
    dump_char_array((char**)array, dim);
    printf("Sorted indexes: ");
    dump_int_array(indexes, dim);
#endif

    free(indexes);
    return 0;
}
Exemplo n.º 2
0
static int validate(char **contextp)
{
    bool res;
    char *context = *contextp;

    sepol_context_t *ctx;
    int rc = sepol_context_from_string(global_state.sepolicy.handle, context,
            &ctx);
    if (rc < 0) {
        fprintf(stderr, "Error: Could not allocate context from string");
        exit(1);
    }

    rc = sepol_context_check(global_state.sepolicy.handle,
            global_state.sepolicy.sdb, ctx);
    if (rc < 0) {
        goto out;
    }

    const char *type_name = sepol_context_get_type(ctx);

    uint32_t len = ebitmap_length(&global_state.assert.set);
    if (len > 0) {
        res = !is_type_of_attribute_set(global_state.sepolicy.pdb, type_name,
                &global_state.assert.set);
        if (res) {
            fprintf(stderr, "Error: type \"%s\" is not of set: ", type_name);
            dump_char_array(stderr, global_state.assert.attrs);
            fprintf(stderr, "\n");
            /* The calls above did not affect rc, so set error before going to out */
            rc = -1;
            goto out;
        }
    }
    /* Success: Although it should be 0, we explicitly set rc to 0 for clarity */
    rc = 0;

 out:
    sepol_context_free(ctx);
    return rc;
}