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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:45:59+00:00 2026-05-28T20:45:59+00:00

The following code: #include <stdlib.h> #include <string.h> int main() { char *s = strdup(keep-alive);

  • 0

The following code:

#include <stdlib.h>
#include <string.h>

int main() {
    char *s = strdup("keep-alive");
    if(strcasestr(s, "close")) {
    }
    free(s);
    return 0;
}

gives the following error in Valgrind:

==13183== Invalid read of size 8
==13183==    at 0x4F53F94: __strcasestr_sse42 (emmintrin.h:685)
==13183==    by 0x4005BF: main (in /home/aaron/dev/strtest)
==13183==  Address 0x51ce048 is 8 bytes inside a block of size 11 alloc'd
==13183==    at 0x4C28F9F: malloc (vg_replace_malloc.c:236)
==13183==    by 0x4EB1441: strdup (strdup.c:43)
==13183==    by 0x4005A5: main (in /home/aaron/dev/strtest)

Has anyone else seen this? This happens with & without optimizations, using gcc 4.6.1.

  • 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-05-28T20:46:00+00:00Added an answer on May 28, 2026 at 8:46 pm

    If this is only happening in valgrind, it’s not an error. It would be undefined behavior for your code to read beyond the end of an object obtained by malloc, but strcasestr is part of “the implementation” and thus can use implementation-specific knowledge: in this case, the fact that over-reading is perfectly safe as long as you don’t cross a page boundary.

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

Sidebar

Related Questions

I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
The code is here: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char*
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
The following code #include <iostream> using namespace std; int main() { const char* const
I have the following code: /* sample.c */ #include<stdio.h> #include<malloc.h> #include<stdlib.h> #includehermes.h #include<string.h> int
I have the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <curl/curl.h> char
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 code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I wrote the following code for string concatnation using pointers in C #include<stdio.h> #include<stdlib.h>
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include

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.