Re: [PATCH 1/8] Add some helpers to manage the strings allocation/deallocation.

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

 



On 02/25/2013 09:19 PM, Zach Brown wrote:
>>    printf("Disk size:\t\t%*s\n", width,
>>         df_pretty_sizes(total_disk, mode));
>>
>> it would be translated (note the '%*s'):
>>
>>    if (mode == DF_HUMAN_UNIT)
>> 	   printf("Disk size:\t\t%*s%s\n", width-2,
>>         	df_pretty_sizes_number(total_disk),
>> 		df_pretty_sizes_unit(total_disk));
>>    else
>> 	   printf("Disk size:\t\t%*lld\n", width, total_disk);
> 
> So use mode as the argument in the second case, just like you did in the
> first.
> 
> printf("Disk dize:\t\t"sz_fmt"\n", sz_arg(total_disk, mode, width));

> 
> #define sz_fmt "%*llu%s"
> #define sz_fmt(v,m,w) width(w, m), scaled(v, m), units(v, m)
I suppose s/sz_fmt/sz_arg/

> And again, the reason we jump through these mildly distasteful hoops is
> that *it gets rid of allocated strings entirely*.
I am not entirely convinced, however if you prepare a patch I will
integrate it quickly

> That bug in df_pretty_sizes() where it allocates a 20 byte buffer to
> store a string that can be 21 bytes long with its null?  It'd just
> vanish.  Not needed.
Good catch

>> To avoid all this mess, we should add another conversion specifier with
>> the function register_printf_function(). Unfortunately I was not able to
>> find the equivalent one for sprintf().
> 
> Doesn't that prevent compile-time verification that the types of the
> format specifiers match the arguments?

Yes this was another cons...

> 
> - z
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux