Sponsored Content
Top Forums Programming Segment fault related to strlen.S Post 302968007 by yifangt on Wednesday 2nd of March 2016 10:44:10 AM
Old 03-02-2016
Segment fault related to strlen.S

Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
Code:
void get_hashes(unsigned int hash[],  unsigned char *in)
{
    unsigned char *str = in;
    int pos = strlen((char *) in);    //This line is of problem!
    hash[0] = RSHash(str, pos);
    hash[1] = DJBHash(str, pos);
    hash[2] = FNVHash(str, pos);
    hash[3] = JSHash(str, pos);
    hash[4] = PJWHash(str, pos);
    hash[5] = SDBMHash(str, pos);
    hash[6] = DEKHash(str, pos);
    hash[7] = murmur(str, (uint64_t) pos, (uint64_t) pos);
}

Then I used gdb to debug, and I got this message:
Code:
Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106    ../sysdeps/x86_64/strlen.S: No such file or directory.

The problem line has been highlighted. Code for the whole program is attached. I used type cast to suppress the warnings at compiling without full understanding.
Can someone explain the error for me, and show me the correct fix?
Thanks a lot!
 

10 More Discussions You Might Find Interesting

1. Programming

Problems with Strlen

hello, i have a problem with strlen. I have written this: for(y=13,z=0; cInBuf!=' ';y++) { cBuf=cInBuf; z++; } len = strlen(cBuf); out=len/2; fprintf(outfile,"F%i",out); If strlen is e.g. 22, it write F22. I want to write F2F2. How can i do this?... (5 Replies)
Discussion started by: ACeD
5 Replies

2. Shell Programming and Scripting

Problem with the strlen function in ksh

Hello, Just a little problem with the ksh function : strlen I want to use this function in this little ksh program : while read line ; do TOTO=$line TOTONB=strlen($TOTO) echo $TOTONB (3 Replies)
Discussion started by: steiner
3 Replies

3. Programming

Segment Fault

When run it, segment fault. What is wrong? #include <stdio.h> #include <stdlib.h> const int max =20; //**************************************************** // Input Matrix //**************************************************** void inMatrixAA(int *AA, int row, int col)... (9 Replies)
Discussion started by: zhshqzyc
9 Replies

4. Programming

'strlen' of a constant string

In a declaration, I have: const char comment_begin = "<!--"; const char comment_end = "-->"; const int comment_begin_len = strlen(comment_begin); const int comment_end_len = strlen(comment_end); When I compile, I get the warnings: emhttpc.c:64: warning: initializer element is not... (10 Replies)
Discussion started by: cleopard
10 Replies

5. Programming

a strange segment fault about ltp-posix test

Hi all In the ltp-posix test,there is a case in open_posix_testsuite\conformance\interfaces\timer_gettime\speculative/6-1.c I run the above code,it will has a segment fault, if I modify it to below,it works well Anybody can tell me why? (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Programming

strlen for UTF-8

My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes. int main(void) { setlocale(LC_ALL, "en_US.UTF-8"); printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Discussion started by: cyler
8 Replies

7. Programming

Data segment or Text segment

Hi, Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment? char *a = "Hello"; I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies

8. Programming

why segment fault,

I always get segment fault, why? can sb help me and modify it, I have spend on much time on #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <string.h> #define MAX 10 pthread_t thread; void *thread1() { int *a; int i, n; ... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

9. Programming

Segment-fault handling for pthreads

Hi I have struggling a week to fix a program , in the begining i got SIGBUS , but after many attempts still the program gets SIGSEGV segment fault , In bellow i post the seg fault log + source codes. would really appreciate if experts help me to fix this segment fault error. any advice is... (2 Replies)
Discussion started by: pooyair
2 Replies

10. Programming

Segment fault for C++ program when return vector

I am trying to reverse complement DNA sequence (string) with a short c++ code using boost library. Code was compiled without any warning/error, but ran into Segmentation fault. My guess is the function to return a vector, but not sure. #include <iostream> #include <fstream> #include <string>... (14 Replies)
Discussion started by: yifangt
14 Replies
QIntValidator(3qt)														QIntValidator(3qt)

NAME
QIntValidator - Validator which ensures that a string contains a valid integer within a specified range SYNOPSIS
#include <qvalidator.h> Inherits QValidator. Public Members QIntValidator ( QObject * parent, const char * name = 0 ) QIntValidator ( int minimum, int maximum, QObject * parent, const char * name = 0 ) ~QIntValidator () virtual QValidator::State validate ( QString & input, int & ) const void setBottom ( int ) void setTop ( int ) virtual void setRange ( int bottom, int top ) int bottom () const int top () const Properties int bottom - the validator's lowest acceptable value int top - the validator's highest acceptable value DESCRIPTION
The QIntValidator class provides a validator which ensures that a string contains a valid integer within a specified range. Example of use: QValidator* validator = new QIntValidator( 100, 999, this ); QLineEdit* edit = new QLineEdit( this ); // the edit lineedit will only accept integers between 100 and 999 edit->setValidator( validator ); Below we present some examples of validators. In practice they would normally be associated with a widget as in the example above. QString str; int pos = 0; QIntValidator v( 100, 999, this ); str = "1"; v.validate( str, pos ); // returns Intermediate str = "12"; v.validate( str, pos ); // returns Intermediate str = "123"; v.validate( str, pos ); // returns Acceptable str = "678"; v.validate( str, pos ); // returns Acceptable str = "1234"; v.validate( str, pos ); // returns Invalid str = "-123"; v.validate( str, pos ); // returns Invalid str = "abc"; v.validate( str, pos ); // returns Invalid str = "12cm"; v.validate( str, pos ); // returns Invalid The minimum and maximum values are set in one call with setRange() or individually with setBottom() and setTop(). See also QDoubleValidator, QRegExpValidator, and Miscellaneous Classes. MEMBER FUNCTION DOCUMENTATION
QIntValidator::QIntValidator ( QObject * parent, const char * name = 0 ) Constructs a validator called name with parent parent, that accepts all integers. QIntValidator::QIntValidator ( int minimum, int maximum, QObject * parent, const char * name = 0 ) Constructs a validator called name with parent parent, that accepts integers from minimum to maximum inclusive. QIntValidator::~QIntValidator () Destroys the validator, freeing any resources allocated. int QIntValidator::bottom () const Returns the validator's lowest acceptable value. See the "bottom" property for details. void QIntValidator::setBottom ( int ) Sets the validator's lowest acceptable value. See the "bottom" property for details. void QIntValidator::setRange ( int bottom, int top ) [virtual] Sets the range of the validator to only accept integers between bottom and top inclusive. void QIntValidator::setTop ( int ) Sets the validator's highest acceptable value. See the "top" property for details. int QIntValidator::top () const Returns the validator's highest acceptable value. See the "top" property for details. QValidator::State QIntValidator::validate ( QString & input, int & ) const [virtual] Returns Acceptable if the input is an integer within the valid range, Intermediate if the input is an integer outside the valid range and Invalid if the input is not an integer. Note: If the valid range consists of just positive integers (e.g. 32 - 100) and input is a negative integer then Invalid is returned. int pos = 0; s = "abc"; v.validate( s, pos ); // returns Invalid s = "5"; v.validate( s, pos ); // returns Intermediate s = "50"; v.validate( s, pos ); // returns Valid Reimplemented from QValidator. Property Documentation int bottom This property holds the validator's lowest acceptable value. Set this property's value with setBottom() and get this property's value with bottom(). See also setRange(). int top This property holds the validator's highest acceptable value. Set this property's value with setTop() and get this property's value with top(). See also setRange(). SEE ALSO
http://doc.trolltech.com/qintvalidator.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qintvalidator.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QIntValidator(3qt)
All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy