Announcement

Collapse
No announcement yet.

valgrind sucks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • valgrind sucks

    Code:
    #include stdio.h
    #include sys/types.h
    #include sys/ipc.h
    #include sys/sem.h
    
    #define KEY 1942
    
    main ()
    {
            struct sembuf sbuf;
            int semid;
    
            semid = semget(KEY, 1, IPC_CREAT | IPC_EXCL | 0777);
            printf("semid = %d\n", semid);
    
            semctl(semid, 0, IPC_RMID);
            puts("destroyed semid");
    }
    Code:
    ==19854== Syscall param semctl(arg) points to uninitialised byte(s)
    ==19854==    at 0xB8AA08: semctl@@GLIBC_2.2 (in /lib/tls/libc-2.3.4.so)
    ==19854==    by 0x8048477: main (in ~/test/semtest)
    ==19854==  Address 0xBEE053D4 is on thread 1's stack

  • #2
    Alternatively, glibc sucks.

    Comment


    • #3
      I laugh at you for taking a stupid degree
      You just wasted six ... no, seven ... seconds of your life reading this sentence.

      Comment


      • #4
        The semget() function returns the semaphore identifier associated with key.

        A semaphore identifier with its associated semid_ds data structure and its associated set of nsems semaphores, see , are created for key if one of the following is true:

        * The argument key is equal to IPC_PRIVATE .

        * The argument key does not already have a semaphore identifier associated with it and (semflg & IPC_CREAT) is non-zero.

        Upon creation, the semid_ds data structure associated with the new semaphore identifier is initialised as follows:

        * In the operation permissions structure sem_perm.cuid, sem_perm.uid, sem_perm.cgid and sem_perm.gid are set equal to the effective user ID and effective group ID, respectively, of the calling process.

        * The low-order 9 bits of sem_perm.mode are set equal to the low-order 9 bits of semflg.

        * The variable sem_nsems is set equal to the value of nsems.

        * The variable sem_otime is set equal to 0 and sem_ctime is set equal to the current time.

        * The data structure associated with each semaphore in the set is not initialised. The semctl() function with the command SETVAL or SETALL can be used to initialise each semaphore.
        With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

        Steven Weinberg

        Comment


        • #5
          That's not a good excuse for throwing errors on delete.

          Comment


          • #6
            Ehrm, I think that the programmers of valgrind didn't expect someone to create a sem just to delete it immediatedly without initialization - who would do that ?

            To be honest, I really don't think valgrind cares a bit about the point that you try to delete it - it just reports that uninitialized data is accessed.
            With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

            Steven Weinberg

            Comment


            • #7
              Bad code. Both the C/C++ Standards demand main() have a return type.

              There are two and only two ways to declare a main function:
              Code:
              int main (void);
              Code:
              int main (int argc, char **argv);
              I am very proud to say I worked on a compiler that would not compile the code in the OP and ***** at you to learn how to program the language properly.

              Sidenote: This thread reminds me of one of my favourite interview questions: How should you handle a destructor that fails?

              I can provide a solution if someone wants it.
              "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
              Ben Kenobi: "That means I'm doing something right. "

              Comment


              • #8
                Asher, you missed a thing - main without a return value isn't acceptable either.

                Bet that Kuci hasn't -Wall set
                With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                Steven Weinberg

                Comment


                • #9
                  Originally posted by BlackCat View Post
                  Asher, you missed a thing - main without a return value isn't acceptable either.

                  Bet that Kuci hasn't -Wall set
                  That's kind of implicit in the requirement. If you declare a return type, you must return a value.
                  "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                  Ben Kenobi: "That means I'm doing something right. "

                  Comment


                  • #10
                    Yeah, but if you don't ask for warns, it still compiles without further notice
                    With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                    Steven Weinberg

                    Comment


                    • #11
                      Only on ****ty compilers.

                      On IBM's compilers, if you write bad code like this you need to add options to tell the compiler to let you be stupid.
                      "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                      Ben Kenobi: "That means I'm doing something right. "

                      Comment


                      • #12
                        AIX would allow it.
                        With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                        Steven Weinberg

                        Comment


                        • #13
                          AIX is not a compiler.
                          "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                          Ben Kenobi: "That means I'm doing something right. "

                          Comment


                          • #14
                            So everyone knows the answer to the destructor question?
                            "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                            Ben Kenobi: "That means I'm doing something right. "

                            Comment


                            • #15
                              cc on an AIX platform would accept it

                              And don't ask me to verify it - we burned our last one in the previous century.
                              With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                              Steven Weinberg

                              Comment

                              Working...
                              X