Sponsored Content
Top Forums Programming Segmentation fault when debugging in C Post 302705439 by Don Cragun on Monday 24th of September 2012 11:33:51 PM
Old 09-25-2012
So, you're getting another error. If you want help, you need to tell us what the error is and give us a way to track it down. This is your program we're trying to debug. Most of us don't have access to your system (or any system running contiki os) and don't have (or want) tinyECC packages on our systems. The comments I've given you are just based on reading your code, knowing what generates a segmentation fault, and a few decades of experience writing C programs.

As to your last comment. If I understand correctly, you now have the following four lines of code in your source:
Code:
int xxx = 2*KEYDIGITS*NN_DIGIT_LEN + 1 + 20+ 20;
uint8_t *C = malloc(xxx*sizeof(uint8_t));
int C_len = 2*KEYDIGITS*NN_DIGIT_LEN + 1 + 20 + 20;
int oct_len = ecc_point2octet(C, C_len, &pbkey_alice, 0);

Wouldn't it make more sense to replace this with:
Code:
int C_len = 2*KEYDIGITS*NN_DIGIT_LEN + 1 + 20 + 20;
uint8_t *C = malloc(C_len*sizeof(uint8_t));
int oct_len = ecc_point2octet(C, C_len, &pbkey_alice, 0);

(since xxx is a duplicate of C_len) or, if C_len isn't used anywhere else, with:
Code:
uint8_t *C = malloc((2*KEYDIGITS*NN_DIGIT_LEN+1+20+20)*sizeof(uint8_t));
int oct_len = ecc_point2octet(C, sizeof(C), &pbkey_alice, 0);

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation Fault

hello all, I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element. ... (3 Replies)
Discussion started by: compbug
3 Replies

2. Programming

Hi! segmentation fault

I have written a program which takes a directory as command line arguments and displays all the dir and files in it. I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
Discussion started by: vijlak
4 Replies

3. Programming

segmentation fault

ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do??? thank... (8 Replies)
Discussion started by: rockgal
8 Replies

4. Programming

Why not a segmentation fault??

Hi, Why I don't receive a segmentation fault in the following sample. int main(void) { char buff; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
Discussion started by: lagigliaivan
22 Replies

5. Programming

segmentation fault

What is segmentation fault(core dumped) (1 Reply)
Discussion started by: gokult
1 Replies

6. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

7. Homework & Coursework Questions

Segmentation Fault

this is a network programming code to run a rock paper scissors in a client and server. I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault. -the segmentation fault is fixed Current problem -Also... (3 Replies)
Discussion started by: femchi
3 Replies

8. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

9. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
All times are GMT -4. The time now is 07:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy