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 8018357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:06:43+00:00 2026-06-04T21:06:43+00:00

I have the following function #include <stdio.h> #include <stdlib.h> #include block.h bool block_equal(const struct

  • 0

I have the following function

#include <stdio.h>
#include <stdlib.h>
#include "block.h"

bool block_equal(const struct block *block1, const struct block *block2) {
    if ((block1 == NULL) ^ (block2 == NULL))
        return false;
    else if (block1 == NULL & block2 == NULL)
        return true;
    else {
        // ... Some stuff
    }
}

When I run it with a pointer to an initialized struct block and NULL, valgrind shows this error (line 6 is the first comparison):

==24444== Conditional jump or move depends on uninitialised value(s)
==24444==    at 0x402E34: block_equal (block.c:6)
==24444==    by 0x4025D3: test_chunks_write (test_chunks.c:22)
==24444==    by 0x4E31FE8: ??? (in /usr/lib/libcunit.so.1.0.1)
==24444==    by 0x4E323C6: ??? (in /usr/lib/libcunit.so.1.0.1)
==24444==    by 0x4E326E7: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
==24444==    by 0x401627: main (tests.c:15)

EDIT: Here is the call of block_equal:

#include <stdlib.h>
#include <CUnit/CUnit.h>
#include "../chunks.h"
#include "../block.h"

void test_chunks_write(void) {
    struct block *block1, *block2;
    block1 = malloc(sizeof(struct block));
    block2 = malloc(sizeof(struct block));
    block1->type = BLOCK_WOOD;
    block2->type = BLOCK_STONE;
    chunks *chunks = chunks_empty();
    coordinates coord1;
    coordinates coord2;
    for (int i=0; i<SPACE_DIMENSION; i++) {
        coord1[i] = i+1;
        coord2[i] = 2*i+5;
    }
    chunks_write_data(&chunks, coord1, block1);
    CU_ASSERT(block_equal(block1, chunks_select_data(chunks, coord1)))
    CU_ASSERT_FALSE(block_equal(block2, chunks_select_data(chunks, coord1)))
    struct block* block3 = chunks_select_data(chunks, coord2);

    ///////////////////////////////////////////////////////////////////////////////////////////////
    // According to the debugger, at this point block2 is 0x605600 and block3 is 0x0
    CU_ASSERT_FALSE(block_equal(block2, block3))
    // ...
}
  • 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-04T21:06:44+00:00Added an answer on June 4, 2026 at 9:06 pm

    Actually, the value is not initialized, so this can point to anything; I don’t know what the debugger does tell me it’s 0x0. I will write my tests differently (testing the address instead, for example).

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

Sidebar

Related Questions

I have the following header file: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <stddef.h>
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include
Have a look at the following code: #include<unistd.h> #include<stdlib.h> #include<stdio.h> #include<string.h> #include<sys/types.h> main() {
I have the following test application: #include <stdlib.h> #include <string.h> #include <stdio.h> int main(void){
I have a problem with the following code: #include mpi.h #include <stdio.h> #include <stdlib.h>
in header file I have defined the following function #ifndef OS_H #define OS_H #include
I have a problem with the following code #include <stdio.h> int main() /* Tidsberäkning
Suppose that we have the following bit of code: #include <pthread.h> #include <stdio.h> #include
Using the following libraries only: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <assert.h> #include
I am only allowed to use following headers #include <stdio.h> #include <stdlib.h> and I

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.