Question
A C function attempts to copy a substring.
#include #include #include char* copy_substring(const char* source, int start_index, int length) { char* dest = (char*)malloc(length + 1); if (dest == NULL) return NULL; strncpy(dest, source + start_index, length); dest[length] = '\0'; // Null-terminate return dest; } int main() { const char* original = "Programming"; // Length 11 char* sub = copy_substring(original, 5, 10); // start_index=5, length=10 if (sub) { printf("Substring: %s ", sub); free(sub); } return 0; } What is the most likely issue with copy_substring when called as in main?Solution
Correct Answer: B (source + start_index points to "mming". length is 10. strncpy will attempt to copy 10 characters starting from 'm'. However, "mming" only has 5 characters. strncpy will read 5 characters from "mming" and then 5 more characters from memory *after* "Programming", potentially causing a read out of bounds.)
The RBI has signed a Currency Swap Agreement with the Maldives Monetary Authority (MMA); the SAARC Currency Swap Agreement came into operation in ______...
‘Save the Narmada’ movement originated as a protest against raising the height of Sardar Sarovar Dam. Some disadvantages of building dams are mentio...
“Wages fund theory” was propounded by?
Select the odd number from the given alternatives.
The price of a product is first reduced by 15% and then increased by 25%. If the final price is ₹690, then find the original cost price.
Match List-1 with List-II and select the correct answer using the code given below the lists:
List-1
A. Dennis Tito
B. Colin...
The 10th schedule of the Indian Constitution is related to?
Who flagged off the Baba Saheb Ambedkar Yatra Bharat Gaurav Tourist train from New Delhi and what is the purpose of this train?
With reference to the Fugitive Economic Offenders Act, 2018, consider the following statements.
1. A Fugitive Economic Offender is a person aga...
Which one of the following accounting concepts is applied by an entity, when events such as new competitor entering in the market and rift between produ...