Ticket #11754: trac_11754_fix_compilation_error_and_a_segfault.patch

File trac_11754_fix_compilation_error_and_a_segfault.patch, 2.3 KB (added by dcoudert, 9 years ago)

complement patch to fix compilation errors and segfaults

  • sage/graphs/graph_decompositions/rankwidth/rw.c

    # HG changeset patch
    # User dcoudert <david.coudert@inria.fr>
    # Date 1328098817 -3600
    # Node ID 171ed1eadf829b3cb28b394c40d0499a8837e3a2
    # Parent  e7c35b58429808c8b1bcc6b46fe08c4be991747b
    trac #11754 -- Fix compilation error and a segfault
    
    diff --git a/sage/graphs/graph_decompositions/rankwidth/rw.c b/sage/graphs/graph_decompositions/rankwidth/rw.c
    a b  
    221221
    222222int init_rw(uint_fast8_t n)
    223223{
    224         num_vertices = n;
    225         adjacency_matrix = malloc(sizeof(subset_t) * n);
    226         slots = malloc(sizeof(uint_fast8_t) * (1ul << n));
    227         cslots = 0;
    228         return((adjacency_matrix && slots) ? 0 : -1);
     224        num_vertices = n;
     225        adjacency_matrix = malloc(sizeof(subset_t) * n);
     226        slots = malloc(sizeof(uint_fast8_t) * (1ul << n));
     227        // This test allows to cope with numerical errors such as
     228        // 2^32 == 0 on some 32bits computers
     229        if( (sizeof(uint_fast8_t) * (1ul << n) == 0) && (n > 0) && (slots) )
     230             return(-1);
     231        cslots = 0;
     232        return((adjacency_matrix && slots) ? 0 : -1);
    229233}
    230234
    231235int init_rw_dec(uint_fast8_t n)
    232236{
    233         if(init_rw(n))
    234                 return(-1);
    235         cslots = malloc(sizeof(subset_t) * (1ul << n));
    236         return(cslots ? 0 : -1);
     237        if(init_rw(n))
     238                return(-1);
     239        cslots = malloc(sizeof(subset_t) * (1ul << n));
     240        // This test allows to cope with numerical errors such as
     241        // 4*2^30 == 0 on some 32bits computers
     242        if( (sizeof(subset_t) * (1ul << n) == 0) && (n > 0) && (cslots) )
     243             return(-1);
     244        return(cslots ? 0 : -1);
    237245}
    238246
    239247void destroy_rw(void)
  • sage/graphs/graph_decompositions/rankwidth/rw.h

    diff --git a/sage/graphs/graph_decompositions/rankwidth/rw.h b/sage/graphs/graph_decompositions/rankwidth/rw.h
    a b  
    2525
    2626// Use data type uint_leastN_t. N is an upper limit on the size of the graphs that can be handled. N=32 seems to be a good compromise for now (the code works well with other values of N).
    2727// uint_leastN_t is faster than uint_fastN_t here, since the bottleneck is cache misses.
     28#ifndef __FLAG_DEFINITION_SUBSET_T__
     29#define __FLAG_DEFINITION_SUBSET_T__ 1
    2830typedef uint_least32_t subset_t;
     31#endif
    2932#define MAX_VERTICES 32
    3033
    3134// Input graph.