Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:11:07+00:00 2026-06-13T13:11:07+00:00

When I run this code, I have error Segmentation fault (core dumped). But without

  • 0

When I run this code, I have error “Segmentation fault (core dumped)”. But without using
mpz_get_str, it is okey.

#include<stdio.h>
#include<gmp.h>
int main()
{
char *A;
mpz_t P,Q;
mpz_init(P);
mpz_init(Q);
mpz_set_str(P,"1201858877187548528922917",10);
mpz_set_str(Q,"1248833599132922783100713",10);

mpz_t PHI,E,K,d;
mpz_init(PHI);
mpz_init(E);
mpz_init(K);
mpz_init(d);

mpz_sub_ui(PHI,P,1);
mpz_sub_ui(K,Q,1);
mpz_mul(PHI,PHI,K);
mpz_set_str(E,"37",10);
mpz_gcd(d,E,PHI);
gmp_printf("d=%Zd\n",d);
mpz_invert(d,E,PHI);
gmp_printf("d=%Zd\n",d);
A=mpz_get_str(A,2,d);

mpz_mul(K,d,E);
mpz_sub_ui(K,K,1);
mpz_divexact(K,K,PHI);



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:11:08+00:00Added an answer on June 13, 2026 at 1:11 pm

    You should initialize your char *A to NULL or 0, otherwise (if it’s not NULL or 0 by chance), GMP will try to write into a random memory address, which will cause a segfault.

    From the GMP documentation: http://gmplib.org/manual/Converting-Integers.html

    If str is NULL, the result string is allocated using the current allocation function (see Custom Allocation). The block will be strlen(str)+1 bytes, that being exactly enough for the string and null-terminator.

    If str is not NULL, it should point to a block of storage large enough for the result, that being mpz_sizeinbase (op, base) + 2. The two extra bytes are for a possible minus sign, and the null-terminator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a Segmentation fault (core dumped) run-time error with the following code:
I have a segmentation fault 11 error when I run the following code. The
I have this code and I couldn't run it because i get this error:
I get this error when I run the code below. I have normally used
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but
When run this code, it gives me a strange error. I have a class
I have C code and I want to compile and run this code in
I have this code to run a slideshow (this is only part of what
I have run this Perl code: #!/usr/bin/perl print content-type: text/html \n\n; print Hello World.\n;
I have this code , and I want to run Log.d every 1000 milis

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.