Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. segmentation error while using mpz_powm in a loop

segmentation error while using mpz_powm in a loop

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
14 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S shrims4u

    the value of array[i] is a bignumber.... Also d and n are initialised... The error is at mpz_powm.... you want me to write the values in numbers???? Actually it differs each time according to the message

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #4

    My, point, although subtle, was to ensure that the values you are passing to that function are valid. Some functions/libraries place the onus of validation solely on the caller (rather than handle the bad input and fail gracefully)

    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    S J 3 Replies Last reply
    0
    • D David Crow

      My, point, although subtle, was to ensure that the values you are passing to that function are valid. Some functions/libraries place the onus of validation solely on the caller (rather than handle the bad input and fail gracefully)

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      S Offline
      S Offline
      shrims4u
      wrote on last edited by
      #5

      yah the values that are passed are proper... The gdb output is as follows.... [New Thread -1208882288 (LWP 9012)] [New Thread -1208879424 (LWP 9009)] [New Thread -1219372144 (LWP 9017)] GNU MP: Cannot allocate memory (size=3368600780) Program received signal SIGABRT, Aborted. [Switching to Thread -1219372144 (LWP 9017)] 0x00110402 in __kernel_vsyscall ()

      M 1 Reply Last reply
      0
      • D David Crow

        My, point, although subtle, was to ensure that the values you are passing to that function are valid. Some functions/libraries place the onus of validation solely on the caller (rather than handle the bad input and fail gracefully)

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        S Offline
        S Offline
        shrims4u
        wrote on last edited by
        #6

        Also i get this message from gdb..... Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1218634864 (LWP 9064)] 0x06d0199c in __gmpz_powm () from /usr/lib/sse2/libgmp.so.3

        1 Reply Last reply
        0
        • D David Crow

          My, point, although subtle, was to ensure that the values you are passing to that function are valid. Some functions/libraries place the onus of validation solely on the caller (rather than handle the bad input and fail gracefully)

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          J Offline
          J Offline
          jeron1
          wrote on last edited by
          #7

          You certainly did not deserve to be down voted for that response.

          S 1 Reply Last reply
          0
          • S shrims4u

            yah the values that are passed are proper... The gdb output is as follows.... [New Thread -1208882288 (LWP 9012)] [New Thread -1208879424 (LWP 9009)] [New Thread -1219372144 (LWP 9017)] GNU MP: Cannot allocate memory (size=3368600780) Program received signal SIGABRT, Aborted. [Switching to Thread -1219372144 (LWP 9017)] 0x00110402 in __kernel_vsyscall ()

            M Offline
            M Offline
            molesworth
            wrote on last edited by
            #8

            shrims4u wrote:

            GNU MP: Cannot allocate memory (size=3368600780)

            I would guess that this is related to the problem. It's tried to allocate 3 Gb of memory, and failed... As to why it's trying to allocate such a big chunk of memory, I couldn't say, but maybe stepping through until you get that error might help pin it down.

            There are three kinds of people in the world - those who can count and those who can't...

            S 2 Replies Last reply
            0
            • J jeron1

              You certainly did not deserve to be down voted for that response.

              S Offline
              S Offline
              shrims4u
              wrote on last edited by
              #9

              i dint understand??? wat is down voting???

              J 1 Reply Last reply
              0
              • M molesworth

                shrims4u wrote:

                GNU MP: Cannot allocate memory (size=3368600780)

                I would guess that this is related to the problem. It's tried to allocate 3 Gb of memory, and failed... As to why it's trying to allocate such a big chunk of memory, I couldn't say, but maybe stepping through until you get that error might help pin it down.

                There are three kinds of people in the world - those who can count and those who can't...

                S Offline
                S Offline
                shrims4u
                wrote on last edited by
                #10

                ill mail the whole program to uall Actually it is a milter which decrypts the incoming mail messages... /* sample_milter - example mail filter module ** ** Copyright © 2004 by Jef Poskanzer . ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** For commentary on this license please see http://www.acme.com/license.html */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libmilter/mfapi.h" ////////////////////////////////////////////////////////////// #include "gmp.h" /* Forwards. */ static void usage( void ); static sfsistat sample_connect( SMFICTX* ctx, char* connhost, _SOCK_ADDR* connaddr ); static sfsistat sample_helo( SMFICTX* ctx, char* helohost ); static sfsistat sample_envfrom( SMFICTX* ctx, char** fromargs ); static sfsistat sample_envrcpt( SMFICTX* ctx, char** rcptargs ); static sfsistat sample_header( SMFICTX* ctx, char* name, char* value ); static sfsistat sample_eoh( SMFICTX* ctx ); static sfsistat sample_body( SMFICT

                1 Reply Last reply
                0
                • S shrims4u

                  i dint understand??? wat is down voting???

                  J Offline
                  J Offline
                  jeron1
                  wrote on last edited by
                  #11

                  When a response receives a 1 vote (located at the bottom right of the response).

                  S 1 Reply Last reply
                  0
                  • J jeron1

                    When a response receives a 1 vote (located at the bottom right of the response).

                    S Offline
                    S Offline
                    shrims4u
                    wrote on last edited by
                    #12

                    will you please help me??? you understood my problem?

                    1 Reply Last reply
                    0
                    • M molesworth

                      shrims4u wrote:

                      GNU MP: Cannot allocate memory (size=3368600780)

                      I would guess that this is related to the problem. It's tried to allocate 3 Gb of memory, and failed... As to why it's trying to allocate such a big chunk of memory, I couldn't say, but maybe stepping through until you get that error might help pin it down.

                      There are three kinds of people in the world - those who can count and those who can't...

                      S Offline
                      S Offline
                      shrims4u
                      wrote on last edited by
                      #13

                      I dint understand what you want me to do...

                      M 1 Reply Last reply
                      0
                      • S shrims4u

                        I dint understand what you want me to do...

                        M Offline
                        M Offline
                        molesworth
                        wrote on last edited by
                        #14

                        Somewhere the program is trying to allocate a very large amount of memory. This is, I think, the cause of your problem. I haven't used this library/package, but I'm basing my conclusion on the error mesage you posted (see my last reply). What I suggest is that you use a debugging tool to step through the program until it generates that error, and take a close look at exactly what is happening at that point. Or post here exactly which line is causing the problem.

                        There are three kinds of people in the world - those who can count and those who can't...

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups