[PATCH] adduser remove some code

Harald Becker ralda at gmx.de
Sat Dec 21 16:22:36 UTC 2013


Hi Tito !

>So I would simplify the code like:
>
>	opt_complementary = "-1:?2:SD:u+";
>	opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir,
>	&pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid);

IMO you miss one fact. The field pw.pw_uid (especially) is
different size and type on different systems/libraries
(sometimes only 16 bit data type). I think getopt32 expects
pointer to an integer or unsigned data type. Writing to 16 bit
data type using a pointer to int would write to unknown location.

Better to use a local variable, and let the compiler do the type
mangling:

  unsigned uid;
  ... getopt32( ..., &uid);
  pw.pw_uid = uid;

But nevertheless you are right, the code parts shall be merged.

--
Harald


More information about the busybox mailing list