LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-22-2014, 02:06 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Program compiles and runs on 12.0-32 compiles on 14.0-64 but won't run.


Hi: A given program compiles and runs on an x86 32-bit machine under 12.0. The same program, compiled on a 64-bit machine under 14.0-x86_64, when run on this machine, gives 'Segmentation fault'. The program is this, the line with the issue having been mark '<-- THIS ONE' (the fourth before the last line in the source):
Code:
#include <usb.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
unsigned short IDVendor=   0x1384;		/*VID must be changed. */
unsigned short IDProduct=  0x8888;		/*PID must be changed. */

static int usbOpenDevice(usb_dev_handle **device, int idvendor, int idproduct)
{
	struct usb_bus *bus;
	struct usb_device *dev;
	usb_dev_handle *udh=NULL;
	int retp, retm,errors;
	char string[256];

	usb_init();
	usb_find_busses();
	usb_find_devices();
	for (bus = usb_busses; bus; bus = bus->next)
	{
		for (dev = bus->devices; dev; dev = dev->next)
		{
			udh=usb_open(dev);
			retp = usb_get_string_simple(udh, dev->descriptor.iProduct, string, sizeof(string));
			retm=usb_get_string_simple(udh, dev->descriptor.iManufacturer, string, sizeof(string));
			if (retp > 0 && retm > 0)
				if (idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct){ *device=udh;return errors=0;}
		}
	}
				 usb_close(udh);return errors=1;
}


int main(int argc, char **argv)
{
	usb_dev_handle *d=NULL;
	unsigned char buffer[3];
	int i, mode, ret;
	char string[256];

	if(argc <2)
	{
		printf("give the voltage value.\n");
		exit(1);
	}
	i=floor(atof(argv[1])*51) ;
 if(i>255){printf("value must be between 0 and 5V\n"); exit(1);} 
	mode=0;
usb_init();
ret=usbOpenDevice(&d, IDVendor,IDProduct);   <-- THIS ONE
if(ret!=0){printf("usbOpenDevice failed\n"); return 0;}

	ret=usb_control_msg(d, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, mode, i, 0, (char *)buffer, sizeof(buffer), 5000);
//	printf("buffer %d \n", buffer[0]);
	return 0;
}
Any known cause?
 
Old 01-22-2014, 01:12 PM   #2
jtsn
Member
 
Registered: Sep 2011
Posts: 925

Rep: Reputation: 483Reputation: 483Reputation: 483Reputation: 483Reputation: 483
The usb_open() call fails and you forgot to check return value of it. Then it tries to call usb_get_string_simple() with a NULL pointer udh that leads to a SIGSEGV.
 
1 members found this post helpful.
Old 01-22-2014, 09:54 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by jtsn View Post
The usb_open() call fails and you forgot to check return value of it. Then it tries to call usb_get_string_simple() with a NULL pointer udh that leads to a SIGSEGV.
Thanks. All boils down then to why it returns a null pointer.

Last edited by stf92; 01-22-2014 at 10:27 PM. Reason: Grammatical error.
 
Old 01-22-2014, 09:55 PM   #4
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860

Rep: Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229
Well, that's why someone wrote DDD.
 
Old 01-22-2014, 10:20 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
But the program is already debugged and running properly on 12.0. So there should be an explanation not envolving the complexities of debugging and recoding. Or stating what precisely should be recoded.
 
Old 01-23-2014, 04:48 AM   #6
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860

Rep: Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229Reputation: 2229
Quote:
Originally Posted by stf92 View Post
But the program is already debugged and running properly on 12.0. So there should be an explanation not envolving the complexities of debugging and recoding. Or stating what precisely should be recoded.
Well, you're the one with all the source code. Start reading. Since the kernel, glibc, libusb, and damn near everything else changed between 12.0 and 14.0, you've got a lot of reading and analysis to do. Let us know how that comes out.
 
1 members found this post helpful.
Old 01-23-2014, 07:43 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I'll be better off working on the old machine. Being new to USB, I've already studied the driver, both the C part and the assembler part exhaustively, toghether with the essentials of USB 1.1 (with the specification in my hand) reaching a point where I have a pretty good understanding of USB (bare bones) and the program. All of this made analitically. No recourse to instruments. Have modified it to my taste and made it run. Though this knowledge is feeble, just acquired and needing the soundness that comes with practice. After all this work, don't feel like getting into the complexities of an O.S. Thanks for pointing out the large differences between 12.0 and 14.0, thus saving me work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple C++ Program: Program Compiles But Won't Run (Segmentation Fault) violagirl23 Programming 3 01-09-2008 01:09 AM
GCC compiles, program runs, but only in a CERTAIN directory The_Nerd Programming 16 03-26-2007 08:28 AM
icculus.org Duke Nukem 3d: compiles fine but won't run mr.gizm0 Linux - Games 1 04-23-2005 05:03 AM
kdevelop compiles but won't run. exodist Linux - Software 0 03-28-2004 08:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration