Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8073919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:29:29+00:00 2026-06-05T14:29:29+00:00

I’m trying to use the Video4Linux2 API , but something peculiar is happening with

  • 0

I’m trying to use the Video4Linux2 API, but something peculiar is happening with the structs that I’m supposed to use to change the various controls on a given camera. For some reason, some of the members aren’t reporting back as changed on assignment. I wrote the following code to simplify the problem:

#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <linux/videodev2.h>
#include <stdlib.h>
#include <errno.h>
#include <stdbool.h>

int setExtendedControl(int id, int value);
int fd = 0;

int main()
{
    setExtendedControl(20, 30);
    return 0;
}

int setExtendedControl(int id, int value)
{
    struct v4l2_ext_control extControl;
    struct v4l2_ext_controls extControls;

    extControl.id = id;
    extControl.value = value;
    extControl.value64 = value;
    extControl.reserved2[0] = 0;
    extControl.reserved2[1] = 0;
    extControl.reserved2[2] = 0;

    //Put the individual control structure into the
    //multi-control container structure and initialize the container
    //as well
    extControls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
    extControls.count = 1;
    extControls.controls = &extControl;
    printf("extControls.controls = %i, extControl = %i\n", (extControls).controls, &extControl);



    extControls.reserved[0] = 0;
    extControls.reserved[1] = 0;
    extControls.reserved[2] = 0;
    extControls.error_idx = 0;

    printf("Verifying settings:\n");
    printf("extControl.id = %i, id = %i\n", extControl.id, id);
    printf("extControl.value = %i, value = %i\n", extControl.value, value);
    printf("extControl.value64 = %i, value = %i\n", extControl.value64, value);
    printf("extControl.reserved2[0] = %i, set to 0\n", extControl.reserved2[0]);
    printf("extControl.reserved2[1] = %i, set to 0\n", extControl.reserved2[1]);
    printf("extControl.reserved2[2] = %i, set to 0\n\n", extControl.reserved2[2]);

    printf("extControls.ctrl_class = %i, V4L2_CTRL_CLASS_MPEG = %i\n", extControls.ctrl_class,
            V4L2_CTRL_CLASS_MPEG);
    printf("extControls.count = %i, set to 1\n", extControls.count);
    printf("extControls.reserved[0] = %i, set to 0\n", extControls.reserved[0]);
    printf("extControls.reserved[1] = %i, set to 0\n", extControls.reserved[1]);
    printf("extControls.reserved[2] = %i, set to 0\n", extControls.reserved[2]);
    printf("extControls.error_idx = %i, set to 0\n", extControls.error_idx);

    printf ("\nRunning secondary check..\n\n");


    int rval;

    //Set up the individual control structure



    //Try to change the control and return the
    //value reporting the outcome.
    rval = ioctl(fd, VIDIOC_S_EXT_CTRLS, &extControls);

    if (extControls.controls != &extControl)
    {
        printf("\n\nLost the pointer on initial set!\n");
    }
    //printf("error_idx after initial set %i\n", extControls.error_idx);

    //printf("extControl = %i, extControls = %i\n");

    //freeStructs(extControl, extControls);

    return rval;
}

When I run this, the “value” and “value64” members aren’t set. The following is the printf outputs:

extControls.controls = -1954893344, extControl = -1954893344
Verifying settings:
extControl.id = 20, id = 20
extControl.value = 0, value = 30
extControl.value64 = 0, value = 30
extControl.reserved2[0] = 0, set to 0
extControl.reserved2[1] = 0, set to 0
extControl.reserved2[2] = 0, set to 0

extControls.ctrl_class = 10027008, V4L2_CTRL_CLASS_MPEG = 10027008
extControls.count = 1, set to 1
extControls.reserved[0] = 0, set to 0
extControls.reserved[1] = 0, set to 0
extControls.reserved[2] = 0, set to 0
extControls.error_idx = 0, set to 0

And here is a small snippet from gdb:

(gdb) step
printf (__fmt=0x400880 "extControls.controls = %i, extControl = %i\n") at /usr/include/x86_64-linux-gnu/bits/stdio2.h:105
105       return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
(gdb) step
setExtendedControl (id=20, value=30) at ioctlTest.c:30
30          extControl.reserved2[0] = 0;
(gdb) step
Hardware watchpoint 2: extControl

Old value =
    {id = 4294960502, size = 32767, reserved2 = {4196309}, {value = 0, value64 = 67750802696962048, string = 0xf0b2ff00000000 <Address 0xf0b2ff00000000 out of bounds>}}
New value =
    {id = 20, size = 32767, reserved2 = {0}, {value = 0, value64 = 67750802696962048, string = 0xf0b2ff00000000 <Address 0xf0b2ff00000000 out of bounds>}}

It’s not happening here, but there have been other instances in a beefier version of this code where the pointer assignment for extControls.controls and int assignment of member extControl.id both fail. What would cause a struct member assignment failure of this nature?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:29:31+00:00Added an answer on June 5, 2026 at 2:29 pm

    Can’t check this myself, but looking at this spec of struct v4l2_ext_control (Table 1), it says:

    Table 1. struct v4l2_ext_control

    __u32   id      Identifies the control, set by the application.
    __u32   reserved2[2]        Reserved for future extensions. Drivers and applications must set the array to zero.
    
    union   (anonymous)      
        __s32   value       New value or current value.
        __s64   value64     New value or current value.
        void *  reserved    Reserved for future pointer-type controls. Currently unused.
    

    Note three things here:

    • value and value64 are part of a union, they occupy the same location in memory
    • reserved2 has size two, so only, reserved2[0], reserved2[1], no reserved2[2] !
    • according to this spec, reserved memory address precedes the union within the struct

    This means that when you set

    extControl.reserved2[2] = 0;
    

    you are actually writing outside the memory assigned to that array, overwriting the data of the union, thus altering “both” value and value64 members at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.