Re: [PATCH v3 1/5] ptp-gadget: Fix issue in enum_object

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

 



On Wed, 8 Feb 2012, Anatolij Gustschin wrote:

> Sometimes not all objects from the image directory are
> imported. Removing this dentry->d_name[] zero-termination
> fixes the problem. As the man-page for readdir(3) states:
> 
>  The only fields in the dirent structure that are mandated
>  by POSIX.1 are: d_name[], of unspecified  size,  with  at
>  most  NAME_MAX  characters preceding the terminating null
>  byte; and (as an XSI extension) d_ino.
> 
> So dentry->d_name[] is zero-terminated, there is no need to
> terminate it.

How about this commit message:

>From readdir(3): "According to POSIX, the dirent structure contains a
field char d_name[] of  unspecified  size,  with  at most NAME_MAX
characters preceding the terminating null byte." In recent Linux versions
d_name is declared as a zero-size array, and is allocated dynamically at
run-time. Therefore calling sizeof() for this struct member is wrong and
useless.

Thanks
Guennadi

> 
> Signed-off-by: Anatolij Gustschin <agust@xxxxxxx>
> ---
> v3:
>  - revised commit message
> 
>  ptp.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 
> diff --git a/ptp.c b/ptp.c
> index 4c4b383..b887176 100644
> --- a/ptp.c
> +++ b/ptp.c
> @@ -2019,7 +2019,6 @@ static int enum_objects(const char *path)
>  		enum pima15740_data_format format;
>  		struct tm mod_tm;
>  
> -		dentry->d_name[sizeof(dentry->d_name) - 1] = '\0';
>  		dot = strrchr(dentry->d_name, '.');
>  
>  		if (!dot || dot == dentry->d_name)
> -- 
> 1.7.1
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux