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
Slurm::Bitstr(3pm)					User Contributed Perl Documentation					Slurm::Bitstr(3pm)

NAME
Slurm::Bitstr - Bitstring functions in libslurm SYNOPSIS
use Slurm; $bitmap = Slurm::Bitstr::alloc(32); if ($bitmap->test(10)) { print "bit 10 is set "; } DESCRIPTION
The Slurm::Bitstr class is a wrapper of the bit string functions in libslurm. This package is loaded and bootstrapped with package Slurm. METHODS
$bitmap = Slurm::Bitstr::alloc($nbits); Allocate a bitstring object with $nbits bits. An opaque bitstr object is returned. This is a CLASS METHOD. $bitmap->realloc($nbits); Reallocate a bitstring(expand or contract size). $nbits is the number of bits in the new bitstring. $len = $bitmap->size(); Return the number of possible bits in a bitstring. $cond = $bitmap->test($n); Check if bit $n of $bitmap is set. $bitmap->set($n); Set bit $n of $bitmap. $bitmap->clear($n); Clear bit $n of $bitmap. $bitmap->nset($start, $stop); Set bits $start .. $stop in $bitmap. $bitmap->nclear($start, $stop); Clear bits $start .. $stop in $bitmap. $pos = $bitmap->ffc(); Find first bit clear in $bitmap. $pos = $bitmap->nffc($n) Find the first $n contiguous bits clear in $bitmap. $pos = $bitmap->noc($n, $seed); Find $n contiguous bits clear in $bitmap starting at offset $seed. $pos = $bitmap->nffs($n); Find the first $n contiguous bits set in $bitmap. $pos = $bitmap->ffs(); Find first bit set in $bitmap; $pos = $bitmap->fls(); Find last bit set in $bitmap; $bitmap->fill_gaps(); Set all bits of $bitmap between the first and last bits set(i.e. fill in the gaps to make set bits contiguous). $cond = $bitmap1->super_set($bitmap2); Return 1 if all bits set in $bitmap1 are also set in $bitmap2, 0 otherwise. $cond = $bitmap1->equal($bitmap2); Return 1 if $bitmap1 and $bitmap2 are identical, 0 otherwise. $bitmap1->and($bitmap2); $bitmap1 &= $bitmap2. $bitmap->not(); $bitmap = ~$bitmap. $bitmap1->or($bitmap2); $bitmap1 |= $bitmap2. $new = $bitmap->copy(); Return a copy of the supplied bitmap. $dest_bitmap->copybits($src_bitmap); Copy all bits of $src_bitmap to $dest_bitmap. $n = $bitmap->set_count(); Count the number of bits set in bitstring. $n = $bitmap1->overlap($bitmap2); Return number of bits set in $bitmap1 that are also set in $bitmap2, 0 if no overlap. $n = $bitmap->clear_count(); Count the number of bits clear in bitstring. $n = $bitmap->nset_max_count(); Return the count of the largest number of contiguous bits set in $bitmap. $sum = $bitmap->inst_and_set_count($int_array); And $int_array and $bitmap and sum the elements corresponding to set entries in $bitmap. $new = $bitmap->rotate_copy($n, $nbits); Return a copy of $bitmap rotated by $n bits. Number of bit in the new bitmap is $nbits. $bitmap->rotate($n); Rotate $bitmap by $n bits. $new = $bitmap->pick_cnt($nbits); Build a bitmap containing the first $nbits of $bitmap which are set. $str = $bitmap->fmt(); Convert $bitmap to range string format, e.g. 0-5,42 $rc = $bitmap->unfmt($str); Convert range string format to bitmap. $array = Slurm::Bitstr::bitfmt2int($str); Convert $str describing bitmap (output from fmt(), e.g. "0-30,45,50-60") into an array of integer (start/edn) pairs terminated by -1 (e.g. "0, 30, 45, 45, 50, 60, -1"). $str = $bitmap->fmt_hexmask(); Given a bit string, allocate and return a string in the form of: "0x0123ABC" ^ ^ | | MSB LSB $rc = $bitmap->unfmt_hexmask($str); Give a hex mask string "0x0123ABC", convert to a bit string. ^ ^ | | MSB LSB $str = $bitmap->fmt_binmask(); Given a bit string, allocate and return a binary string in the form of: "0001010" ^ ^ | | MSB LSB $rc = $bitmap->unfmt_binmask($str); Give a bin mask string "0001010", convert to a bit string. ^ ^ | | MSB LSB $pos = $bitmap->get_bit_num($n); Find position of the $n-th set bit(0 based, i.e., the first set bit is the 0-th) in $bitmap. Returns -1 if there are less than $n bits set. $n = $bitmap->get_pos_num($pos); Find the number of bits set minus one in $bitmap between bit postion [0 .. $pos]. Returns -1 if no bits are set between [0 .. $pos]. SEE ALSO
Slurm AUTHOR
This library is created by Hongjia Cao, <hjcao(AT)nudt.edu.cn> and Danny Auble, <da(AT)llnl.gov>. It is distributed with SLURM. COPYRIGHT AND LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-03-16 Slurm::Bitstr(3pm)
All times are GMT -4. The time now is 02:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy