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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:35:39+00:00 2026-06-13T22:35:39+00:00

I am stuck fixing some legacy RAID code (Yes, I pulled the shortest straw).

  • 0

I am stuck fixing some legacy RAID code (Yes, I pulled the shortest straw).

Heres a snippet of code I found.

#define FLAG_LENGTH 256

#code
char str[FLAG_LENGTH-1]

strlcat(&str,source_ptr,FLAG_LENGTH);

There is comment right above the str declaration which says the size was 1 less for a good reason, but the generous comment writer hasnt mentioned the “good reason”.

If I understand the implementation of strlcat correctly, it NULL terminates all strings no matter what,and as size if 256 would add it to the 256th character i.e index 255, of a string of size 255, i.e last index 254. Arent we overflowing the string?? Or is there some hidden genius in doing this (Asking purely based on the comment)

  • 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-13T22:35:40+00:00Added an answer on June 13, 2026 at 10:35 pm

    Yes, this code is dangerously wrong. There’s really nothing else to say. I’m guessing somebody accidentally wrote -1 instead of +1, but there’s no reason for any discrepancy between the size of the array and the size passed to strlcat.

    By the way, I think this kind of bug serves as a great example of why magical “safe” string interfaces are no panacea. Writing solid code requires not being an idiot. Language or library features will not protect you from your own stupidity.

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

Sidebar

Related Questions

So I am stuck with fixing/maintaining another programmers code (blech) I am a firm
Been stuck on this for ages. Currently learning Django and done some bits on
I need some help in fixing the below issue. I had transaction blocks in
For Google Maps V3, I have some code that created a marker when a
we're trying to sort out some conventions for handling dependencies with code checked into
I'm a bit stuck with refactoring my code to make a method available to
I have some terribly written ASP.NET code that is just not working right (go
I'm testing for the first time on a real device, and after fixing some
I'm building some functional tests for a web site using Selenium, and I'm stuck
Stuck on KVCs in Obj-C again. I am wanting to use KVC to find

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.