What is wrong with this code?

What is wrong with this code?

Attached: 450eab9d.png (454x251, 7K)

Other urls found in this thread:

tutorialspoint.com/c_standard_library/c_function_sscanf.htm
twitter.com/SFWRedditVideos

Possible to overwrite the array.

[spoiler]Also you're trying to dogwhistle some SJW shit aren't you[/spoiler]

It assumes the person's gender

It's not Javascript

Attached: 1539367976885.png (654x702, 415K)

Call me retarded but doesn't scanf have guards against that? If I input 17 characters to a 16 byte array it would just stop at 16, right?

coming from python
can you not just make a char array of undefined length?
always seemed so strange to me that you have to preallocate the size

All scanf sees is a pointer to a buffer. It has no idea how large that buffer is.

This thread again?

there's dynamic allocation

scanf cannot posibly know the available space in the array since it gets handed a pointer.

Attached: 1536901607936.gif (384x269, 774K)

it should be
scanf("%s", &name)

std::string in c++ automatically handles lengths under the hood.

No it shouldnt, are you insane? You want a pointer, name is already char*

scanf("%s", ...) is inherently dangerous, like gets().
You need to add a max string length, or use a functions which isn't as shitty.
char s[16];
scanf("%.15s", s);
char s[16];
fgets(s, sizeof(s), stdin);
// POSIX standard, but not ISO standard
char *s;
scanf("%ms", &s);
...
free(s);
// POSIX standard, but not ISO standard
char *s = NULL;
size_t n = 0;
getline(&s, &n, stdin);
...
free(s);
fgets and getline aren't exactly the same, since they're line-based instead of word based, but they're the functions you'd actually want to use most of the time.

>What is wrong with this code?
You post it every day.

fname is a char array but it implicitly converts to a char pointer.

Shit I meant over-flow- the array
Oh well at least Jow Forums knows what I meant.

name is a pointer to char.
&name is address of pointer to char.

name is not a pointer, you can not reassign its value. Name is an array/memory reference.

No, &name's type is a pointer to an array. You don't know C.

name is a char array, which decays to a pointer to char.
&name is a pointer to a char array, which decays into a pointer to its first element.

>&name is a pointer to a char array, which decays into a pointer to its first element.
Unless I misunderstood what you meant, it's not valid syntax unless you also dereference name.

char* ptr = &name; // invalid syntax
char* ptr = &name[0]; // valid syntax

The font rendering, you fucking faggot.

char (*ptr)[16] = &name;

POINTERS ARE NOT ARRAYS

Holy shit man, I was looking for these guys!
Legendary.

You're retarded open up a compiler.

>open up a compiler

>open up a compiler
const char* str = "Fuck, you're retarded";
char arr[32];
char* ptr;

ptr = str; // Fine, because ptr is a pointer
arr = str; // Doesn't work, because arr is NOT a pointer (retard)

because you cant do
scanf("%15s",name);
right op?

What would your code do if I opened up its memory space with a hex editor and started changing shit arbitrarily? Could it handle that? No? Then it's trash.

// a.c
int array[3] = { 5, 10, 15 };
// b.c
#include

extern int *array;

int main(void)
{
for (int i = 0; i < 3; ++i)
printf("%d\n", array[i]);
}
gcc -o prog a.c b.c
./prog
Tell me the result.

How good are you with Unix Jow Forums?
Pic related is babby's first exploit, can you spot it?

Attached: Lbedrtx.png (832x45, 45K)

Well you have to ask the OS to reserve a specific amount of memory for you. What Python does under the hood is allocate an array with a small size (I'm making this up, but let's say 64) and when you add a 65th element it allocates a new array that is circa double the size, then it moves all the elements from the old array to the new one. In C++ std::vector does the same, in C you have to do this yourself (or use a lib I guess).

it's written in an ancient unsafe language

>nothing to handle memory corruption due to deep space radiation exposure
>nothing to handle EMP from a Chinese nuke hitting Silicon Valley

in the trash it goes

Exclusively visible to my naked eye.

A racistly small name buffer.

Fucking retards, the lot of you.

Attached: Untitled.png (461x609, 17K)

>naked
Is this sexual harassment?

This thread again? Geez get a life.

Passing the array in gives you the address of the first element implicitly. So yes, it's a pointer.

No, it's an implicit conversion. That's like saying char c; is a double because you can pass it to a function that accepts a double.

The formatting is odd to me, preference but still, missing void declaration for parameters, and I think I would use gets_s instead but I'm not sure because I don't know c or much about programming but I think it would help with the buffer issue that people brought up.

>missing void declaration for parameters
Not strictly necessary.
>gets_s
Annex K is shit and nobody implements it.

It input line(s) should be
scanf("%15[^\n]s", name);
while (getchar() != '\n');

I dunno, maybe there could be created a symlink in the directory?

I think you should use gets();

It's funny because if you actually bother compiling this (without turning certain flags off) and running it on a modern OS, stack protection will make this a non-issue. It still hurts my eyes to look at it though.

Out of bounds writes and problematic gender assumptions

Oh great, it's this shitty thread again.

It's the wildcard character, you can give it any argument you want, including a completely new path

Its in C

It was written by a freshman CS student

>ptr = str
Not fine, because you're converting const to non-const without a cast.

Try typing more characters than can be stored in the buffer. The program might crash, or it might do something else entirely.

there's like a fuckton of secure scanf alternatives, both in c standard and windows-specific

unironically this.

The problem with this code is that it gets posted every fucking week. Just fuck off and die, nobody cares about your poorly implemented first C program.

It's not 1989.

#include
#include

int main(){
std::coutname;
std::cout

>C++
off yourself

>look at me mommy
>im hatin what the kool kidz h8
>arnt i smart

it's not secure.
setting up for a potential overflow with that array
using the exploitable standard scan / print.

if scanf/printf is so insecure, why does it still exist?

printf is not really insecure, scanf is still round because it is mandated by the C standard

Using an unsafe language.

>be C
>a simple 'hello world, johnny.' can kills your computer.

Why would you not use namespace std for this isolated program?

you didn't include string

tutorialspoint.com/c_standard_library/c_function_sscanf.htm

you're all mentally retarded

>be C
>hipsters and pajeets fear you and will never touch your project
>in exchange for this, all you have to do is be a little careful with your code

Seems like a fair price to me.

Attached: 1536397728610.gif (500x564, 230K)

>you're all mentally retarded
Always 2 times more mentally retarded than thou

checkmate

When the user enters more than 15 characters, everyone will die.

>namefag
>calling others retarded

Attached: ac_apollo.gif (500x275, 94K)

Stop making him a namefag

>having this bad of a test case
The entire discussion is about going over the array size, which is CS 101; look up undefined behavior

Welcome to shitty-C, the retard language where arrays decay to pointers and where string functions will keep going until they encounter a null byte, even if what they're reading isn't ascii (let alone UTF-8, C doesn't know that).

spaces instead of tabs.

Unless you're programming for the MS-DOS, not really.
The CPU itself will catch your naughty behavior and snitch to the OS, that will terminate it on the spot.

FFS, how hard is it?

Attached: Captura de ecrã 2018-10-18, às 20.37.26.png (1824x1768, 555K)

You CIA niggers, you think I don't have a brain? I didn't go to MIT

Attached: Captura de ecrã 2018-10-18, às 20.42.02.png (2404x2080, 1.04M)

Attached: bf.png (384x302, 10K)

This looks like an extremely unsafe and exploitable operation you have there

>using GNU garbage

And would you like to explain my actions affect what that nigger puts in the name box?

By responding and even acknowledging that he exists

Then start talking or GTFO

LOLTF

you're using the wrong language

#include
#include

using namespace std;

int main ()
{
cout s;
cout

Attached: kys.jpg (2048x1762, 125K)

le overly complicated explanation man strikes again.

correct answer: use .net

Retard

>he's using a 40+ year old language

Attached: 1478881152513.jpg (599x461, 35K)

Buffer Overflow

you can create a pointer and allocate space using malloc(), calloc(), or realloc(), which is what python does anyway, it just does it for you