[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH v2 2/9] loop:refactor: extract subfunction get_next_free_loop()
From:       Xiaoming Ni <nixiaoming () huawei ! com>
Date:       2022-11-21 13:48:45
Message-ID: 600c6400-5e80-013f-0b6b-0522baf201e1 () huawei ! com
[Download RAW message or body]

On 2022/11/21 15:50, Kang-Che Sung wrote:
> On Mon, Nov 21, 2022 at 9:19 AM Xiaoming Ni <nixiaoming@huawei.com> wrote:
>> static int get_next_free_loop(char *dev, size_t dev_size, int id)
>> {
>>           int loopdevno = get_free_loop();
>>           if (loopdevno >= 0) {
>>                   snprintf(dev, dev_size, LOOP_FORMAT, loopdevno);
>>                   return 1; /* use /dev/loop-control */
>>           }
>>           if (loopdevno == -2) {
>>                   snprintf(dev, dev_size, LOOP_FORMAT, id);
>>                   return 2;
>>           }
>>           return -1; /* no free loop devices */
>> }
>>
>> If the dev_size parameter is added to get_next_free_loop(), the code
>> size increases, Is it worth?
>>
>> function                                             old     new   delta
>> set_loop                                             734     744     +10
>> ------------------------------------------------------------------------------
>> (add/remove: 0/0 grow/shrink: 1/0 up/down: 10/0)               Total: 10
>> bytes
> 
> No, that isn't what I mean. sprintf() is faster than snprintf() when
> we are sure the string buffer would never overflow.
> Just keep using sprintf() here but add a statement before it:
> `assert(dev_size >= LOOP_NAMESIZE);`
> .
> 

thanks
  I'll add const modifiers in the next version.

Thanks


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic