Re: [PATCH 2/2] mdadm: add map_num_s()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/20/22 07:18, Mariusz Tkaczyk wrote:
> map_num() returns NULL if key is not defined. This patch adds
> alternative, non NULL version for cases where NULL is not expected.
> 
> There are many printf() calls where map_num() is called on variable
> without NULL verification. It works, even if NULL is passed because
> gcc is able to ignore NULL argument quietly but the behavior is
> undefined. For safety reasons such usages will use map_num_s() now.
> It is a potential point of regression.

Hi Mariusz,

I'll be honest with you, I don't like assert(), I consider it a lame
excuse for proper error handling. That said, not blaming you as this is
old code and it would take a lot of cleaning up, so this is better than
nothing.

I have applied it with one minor change:

> diff --git a/mdadm.h b/mdadm.h
> index 6aff034..9e9c4d8 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -769,7 +769,7 @@ extern int restore_stripes(int *dest, unsigned long long *offsets,
>  #endif
>  
>  #define SYSLOG_FACILITY LOG_DAEMON
> -
> +char *map_num_s(mapping_t *map, int num);
>  extern char *map_num(mapping_t *map, int num);
>  extern int map_name(mapping_t *map, char *name);
>  extern mapping_t r0layout[], r5layout[], r6layout[],

I changed this to be extern to be consistent with the other declarations.

Thanks,
Jes




[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux