Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config-pin seg fault on GetGpio #234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tools/pmunts_muntsos/config-pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static int GetGpio(char *pin, int print) {
char cmd[255];
char cmdout[255];
char *temp_pin_name;
char pin_name[32];
char pin_name[32]={0};
char chip;
char gpio_chip[3];
int gpio, status;
Expand Down Expand Up @@ -108,16 +108,21 @@ static int GetGpio(char *pin, int print) {
strtok(NULL, " ");
temp_pin_name = strtok(NULL, " "); // Pin name is the third word of gpioinfo output

strncpy(pin_name, temp_pin_name + 1, strlen(temp_pin_name) - 1); // Remove quotes surrounding pin name
pin_name[strlen(temp_pin_name) - 2] = '\0'; // Need to manually add null terminator with strncpy
strcat(pin_name,temp_pin_name); // Get pin name with quotes
while(temp_pin_name[strlen(temp_pin_name)-1]!='"') //if no end quote
{
strcat(pin_name," ");
temp_pin_name = strtok(NULL, " "); //get next word
strcat(pin_name,temp_pin_name);
}

// Run gpiofind [pin_name]

strcpy(cmd, "gpiofind ");
strcat(cmd, pin_name);
RunShellCmd(cmd, cmdout, sizeof(cmdout));

if(status == -1 || cmdout[0] == '\0') // Check for error or empty string (meaning pin could not be found)
if(status == -1 || cmdout[0] == '\0' || strlen(cmdout)<9) // Check for error or empty string (meaning pin could not be found)
return -1;

// Get GPIO chip (parse gpiofind output)
Expand Down