On Wed, 11 Sep 2024 10:07:25 +0800
"WanRenyong" <wa...@yunsilicon.com> wrote:

> +
> +     sprintf(path, "%s/device/uevent", dev_path);

better to use snprintf for safety

> +     while (fgets(line, sizeof(line), file) == line) {
> +             size_t len = strlen(line);
> +
> +             /* Truncate long lines. */
> +             if (len == (sizeof(line) - 1)) {
> +                     while (line[(len - 1)] != '\n') {
> +                             int n = fgetc(file);
> +
> +                             if (n == EOF)
> +                                     goto out;
> +                             line[(len - 1)] = n;
> +                     }
> +                     /* No match for long lines. */
> +                     continue;
> +             }

If you have to deal with long lines better to use something
like getline() that handles arbitrary length.

Reply via email to