@@ -68,7 +68,13 @@ tm_topology_t * tgt_to_tm(char *filename)
68
68
printf ("Reading TGT file: %s\n" ,filename );
69
69
70
70
71
- fgets (line ,1024 ,pf );
71
+ if (NULL == fgets (line ,1024 ,pf )) {
72
+ /* either an error has occurred (and is in an unknown state) or
73
+ we hit EOF and line is empty. Either way, make line the
74
+ empty string to avoid errors later */
75
+ line [0 ] = '\0' ;
76
+ }
77
+
72
78
fclose (pf );
73
79
74
80
s = strstr (line ,"tleaf" );
@@ -159,7 +165,13 @@ double ** topology_to_arch(hwloc_topology_t topology)
159
165
double * * arch = NULL ;
160
166
161
167
nb_proc = hwloc_get_nbobjs_by_type (topology , HWLOC_OBJ_PU );
162
- arch = (double * * )MALLOC (sizeof (double * )* nb_proc );
168
+ if (nb_proc < 0 ) {
169
+ return NULL ;
170
+ }
171
+ arch = (double * * )malloc (sizeof (double * )* nb_proc );
172
+ if (NULL == arch ) {
173
+ return NULL ;
174
+ }
163
175
for ( i = 0 ; i < nb_proc ; i ++ ){
164
176
obj_proc1 = hwloc_get_obj_by_type (topology ,HWLOC_OBJ_PU ,i );
165
177
arch [obj_proc1 -> os_index ] = (double * )MALLOC (sizeof (double )* nb_proc );
@@ -534,7 +546,9 @@ int tm_topology_add_binding_constraints(char *constraints_filename, tm_topology
534
546
535
547
/* compute the size of the array to store the constraints*/
536
548
n = 0 ;
537
- fgets (line , LINE_SIZE , pf );
549
+ if (NULL == fgets (line , LINE_SIZE , pf )) {
550
+ line [0 ] = '\0' ;
551
+ }
538
552
l = line ;
539
553
while ((ptr = strtok (l ," \t" ))){
540
554
l = NULL ;
@@ -545,7 +559,9 @@ int tm_topology_add_binding_constraints(char *constraints_filename, tm_topology
545
559
tab = (int * )MALLOC (n * sizeof (int ));
546
560
547
561
rewind (pf );
548
- fgets (line , LINE_SIZE , pf );
562
+ if (NULL == fgets (line , LINE_SIZE , pf )) {
563
+ line [0 ] = '\0' ;
564
+ }
549
565
fclose (pf );
550
566
l = line ;
551
567
i = 0 ;
0 commit comments