Like Tree1Likes

I need to see a function return address.

This is a discussion on I need to see a function return address. within the C Programming forums, part of the General Programming Boards category; AS I said the program was kind of hacked together from another program, the program analyses a poker hand history. ...

  1. #16
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    AS I said the program was kind of hacked together from another program, the program analyses a poker hand history.
    IT worked on one site so I hacked it about to get it to work another site, but it was not designed to work on that site
    so perhaps no surprise it has an issue, more surprising it worked in the first place.

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,246
    Luck rather than good planning, I'd say.

    Also, just because a program appeared to work on "one site" doesn't mean it actually did. It probably just means the symptoms didn't become obviously visible.
    Right 98% of the time, and don't care about the other 3%.

  3. #18
    Registered User
    Join Date
    May 2009
    Posts
    2,542
    This below is not a best way to do debugging printf(s)
    Code:
    printf("\n debug21 <%s>",&var1[19+namelen]);
    This below is better in most if not all use cases.
    Code:
    fprintf(stderr, " debug21 <%s>\n",&var1[19+namelen]);
    But, this is likely a problem that can be solved much faster using a debugger.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  4. #19
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Click_here View Post
    ... That doesn't account for all the variables that you have used

    I'd say that you are going out of bounds on one of those arrays



    No worries.

    Well it was not that issue, I fixed that and it still fails, but no surprise there are bugs there.
    One thing which can happen is that the data it runs on can change as the poker site is responsible for that and can change it when my program does not expect it.

    Yes I could be out of bounds on the arrays.
    One thing they can do is change the length of player names or stuff like that.

    The problem seems to occur on exit from that routine all the time (when it does occur)

  5. #20
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    Quote Originally Posted by esbo View Post
    AS I said the program was kind of hacked together from another program, the program analyses a poker hand history.
    IT worked on one site so I hacked it about to get it to work another site, but it was not designed to work on that site
    so perhaps no surprise it has an issue, more surprising it worked in the first place.
    I don't think it's surprising, this is what undefined behaviour does.

    It still sounds like you are trying to read/write out of bounds on one of those arrays.
    Fact - Beethoven wrote his first symphony in C

  6. #21
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    OK I found something I search the header of each game for the table name.

    When I find it I print it in my debug file as below

    Tablevar2 <201561Table>
    Tablevar2 <201390Table>
    Tablevar2 <201936Table>

    So there are dozens of them until I get this one..


    Tablevar2 <#2439431Speed>

    Then after that that line never appears although it does do a lot of processing before it falls over, it it passed several tables but missed them.

    So it seems like that would cause problems

  7. #22
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    472
    Post some actual code so we can see what your intent/issue is clearly.

    Side-note: you dont need to call fflush(stdout) if your printf() call has a \n (anywhere) in the output.

  8. #23
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    You could use an assert to see if the input to the array is ok

    Here is an example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    
    
    //define NDEBUG
    
    
    int main(int argc, const char *argv[])
    {
        int arr[6] = {0};
        int another_arr[10] = {0,1,4,3,5,67,3,5,4,9};
        int user_in;
        int i;
    
        printf(">>");
        fflush(stdout);
    
        if (scanf("%d", &user_in) == 1)
        {
            assert(user_in <= 10);
            assert(another_arr[user_in] < 6);
    
            arr[another_arr[user_in]] = 1;
        }
    
        for (i=0; i<6; i++)
        {
            printf("%d ", arr[i]);
        }
    
    
        fflush(stdout);
    
    
        return EXIT_SUCCESS;
    }
    When you have finished debugging, you define NDEBUG and all the asserts go away. Note that it is bad form to keep asserts in your final code, so don't use asserts for things that may vary at run time, like the return value for malloc.
    Last edited by Click_here; 01-10-2013 at 08:27 PM. Reason: Added colour
    Fact - Beethoven wrote his first symphony in C

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by Click_here
    You could use an assert to see if the input to the array is ok
    You could, but you shouldn't, because:
    Quote Originally Posted by Click_here
    Note that it is bad form to keep asserts in your final code, so don't use asserts for things that may vary at run time, like the return value for malloc.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #25
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    So here are examples of the different headers.

    #Game No : 9056447907
    ***** Hand History for Game 9056447907 *****
    $5 USD NL Texas Hold'em - Thursday, March 25, 05:48:56 GMT 2010
    Table Table 167843 (Real Money)


    #Game No : 11599958230
    ***** Hand History for Game 11599958230 *****
    $10 USD NL Texas Hold'em - Thursday, March 29, 18:15:48 EDT 2012
    Table Speed #2413385 (No DP) (Real Money)
    So there may be a clue in that and the last post, bit hard to debug cos there is so much data.

    One thing is if it does not find the table it may not find the players, which can change. However I will always be at the table, but other players will not.



    I have two table I use, one for the the current table and one for a list of all the players I ever play against. I store them in a big l list in my big table, then search for a player and use his existing data or create a new entry if I have never met him before.

    For example

    pname[cpid[player_no]].stack-=betval;


    Pname is my 'big list' but cpid[player_no] is my local list for the table.
    So .stack would be his overall profit/loss.

    So player_no would only be form 1-10 but cpid[player_no] could be a number from 1-10,000 perhaps. So pname[4736].stack would be the stack for that particular player.
    Bit confusing perhaps.

  11. #26
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by nonpuz View Post
    Post some actual code so we can see what your intent/issue is clearly.

    Side-note: you dont need to call fflush(stdout) if your printf() call has a \n (anywhere) in the output.
    Maybe not I just put it in to be sure.

  12. #27
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    I stand by my suggestion of assert to help the OP in their example.

    @OP: Just make sure that you don't count on it stopping your code at run time.
    Fact - Beethoven wrote his first symphony in C

  13. #28
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,343
    How large is pname? How large is cpid?

    Assert that the array input is not out of bounds
    Fact - Beethoven wrote his first symphony in C

  14. #29
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Code:
    typedef struct {
    			char name[40];		
    			float stack;	
    			float dolstack;
    			float tempval;
    			int	gamesplayed;
    			int tookpart;
    			int tookpart3;
    			int tookpart5;
    			int tookpart8;
    			int five;
    			int eight;
    			int three;
    			int unmatched;
    			int pfr;
    			int afr;
    			int atr;
    			int arr;
    			int showdin;
    			float win;
    			float win5;
    			int showdwon;
    			float tempstack;
    			} PLYR;
    			
    PLYR pname[MAXLIST];	// maxlist is about 10000
    
    
    int cpid[11]; /* player id number */ so this hold the index numbers of the big table for the upto ten players playing.
    What I am thinking is that I may not be resetting some of my per game data, so something may be over flowing, need to investigate more I think.

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by Click_here
    I stand by my suggestion of assert to help the OP in their example.

    @OP: Just make sure that you don't count on it stopping your code at run time.
    That's why you should take a seat

    The problem here is that the input is not what is expected. An assertion is thus a wrong -- or at least insufficient -- approach, since it does not document a post-condition (or pre-condition) that can be guaranteed to be satisfied by the programmer. Rather, check the input and deal with it, e.g., skip it, log it, report the problem to the user, etc.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function calls and return address
    By acpower in forum C Programming
    Replies: 2
    Last Post: 06-05-2012, 05:58 AM
  2. Returning Address with Return Statement?
    By Waleed Mujeeb in forum C++ Programming
    Replies: 5
    Last Post: 03-23-2012, 05:47 AM
  3. how to return address of a pointer?
    By spotty in forum C Programming
    Replies: 1
    Last Post: 02-11-2010, 07:11 PM
  4. modifying a return address of a function
    By jay1313 in forum C Programming
    Replies: 3
    Last Post: 09-18-2008, 09:09 AM
  5. Replies: 2
    Last Post: 12-07-2004, 01:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21