Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
more falafel please
Feb 26, 2005

forums poster

Plorkyeran posted:

I think the suggested limit of 50 characters for the subject line is overly short (especially when you're doing things like putting ticket numbers in the subject), but if you're going way over it then you've probably failed to actually write a subject line and should put most of that in the body.

I don't really see a reason to give a gently caress about what the line character limit for the body is. I just write some text then hit the word wrap button in my text editor.

[artbuild] [engine] [jira-420] Fix crash whe...

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

zergstain posted:

Is that some new syntax? It looks like you are declaring a function called &&() as opposed to operator&&().

No, it is supposed to have the operator part, but I cut it out by mistake when simplifying the signature :v:

The original signature looks like this

C++ code:
    template<typename MatcherLHS, typename MatcherRHS>
    std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>>
        operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) {
        return { lhs, rhs };
    }
to enable the overload only when relevant.

--------------------------


Ola posted:

Thank you, very interesting example! If it's easy to use and works well, obviously no problems. But the topic did come up as variadic being harder to handle than non-variadic. And the case you illustrate doesn't have to be variadic to solve the usefulness of having an arbitrary number of matchers: A single matcher can be a list of one matcher. The && or || or other operators concatenate lists of matchers according to appropriate rules, then return lists of matchers. Obviously these get evaluated before the function call. The function called which deals with matching takes two arguments, something to be matched and a list of matchers. No need for arbitrary amounts of arguments, no need for variadics.

Xarn posted:

So far so good, the type even has a base class that could in theory be used to hold it in a single-type container... except that loses access to match, because you obviously cannot have templated virtual member functions. So, if you are to store multiple matchers like this (e.g. when you are constructing a generic MatchAll matcher), and use them to do matching, you have to keep around their actual types.

Xarn
Jun 26, 2015

Ola posted:

Yeah, I definitely missed that part, because I wasn't rubbing my fingers and sniffing the finer grains of the stupid bullshit.



"Ideal values"

wow, that's an amazing amount of circular reasoning and bullshit stats

Gaukler
Oct 9, 2012


IBM punch cards were 80 characters wide and teletypes followed that example. 72 is also an IBM-ism as far as I know. The FORTRAN reference hinted at it, but at least the last time I was forced to use a z Series mainframe with the godawful text interface, 8 characters between the left and right gutters were taken up with things like line numbers and other control chars. This was writing PL/I and JCL, not FORTRAN.

Why the world is still stuck on this limit, I have no idea. Blocks of text are generally easier to read than long lines with continuation, so I guess an arbitrary traditional limit is better than nothing?

xtal
Jan 9, 2011

by Fluffdaddy
https://baymard.com/blog/line-length-readability

quote:

The optimal line length for your body text is considered to be 50-60 characters per line, including spaces (“Typographie”, E. Ruder). Other sources suggest that up to 75 characters is acceptable.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Gaukler posted:

Why the world is still stuck on this limit, I have no idea. Blocks of text are generally easier to read than long lines with continuation, so I guess an arbitrary traditional limit is better than nothing?

Never underestimate the power of peer pressure from dead people.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

This thread and its replies are great https://twitter.com/danluu/status/1115707741102727168

zergstain
Dec 15, 2005

Xarn posted:

No, it is supposed to have the operator part, but I cut it out by mistake when simplifying the signature :v:

The original signature looks like this

C++ code:
    template<typename MatcherLHS, typename MatcherRHS>
    std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>>
        operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) {
        return { lhs, rhs };
    }
to enable the overload only when relevant.

--------------------------

I'm really not up to date on C++, so I honestly wasn't sure.

Xarn
Jun 26, 2015

I like this one the best, because the first time I read it, I thought they were joking.

https://mobile.twitter.com/decivilizator/status/1115873168445644800

Macichne Leainig
Jul 26, 2012

by VG
The whole “ideal values” thing from the Linux kernel commits is really dumb. All that data shows is that 50 characters is the most common length, not that it is “ideal,” which is something that will vary from user to user anyway.

How many commits of those are just “fixed a few bugs” or “asdfghjkl” or whatever too?

Make it configurable and let people define their own limits, boom, everyone’s happy.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

Protocol7 posted:

How many commits of those are just “fixed a few bugs” or “asdfghjkl” or whatever too?
I don't think the kernel accepts commits with useless messages.

Protocol7 posted:

Make it configurable and let people define their own limits, boom, everyone’s happy.
git imposes no such limits

OddObserver
Apr 3, 2009

Readability for general text and commit messages are different issues anyway.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Xarn posted:

I like this one the best, because the first time I read it, I thought they were joking.

https://mobile.twitter.com/decivilizator/status/1115873168445644800

lol "nerd-driven studies"

I only take advice on typography from high school football players. It is quite hard to hear their advice clearly from the inside of a locker though.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Protocol7 posted:

The whole “ideal values” thing from the Linux kernel commits is really dumb. All that data shows is that 50 characters is the most common length, not that it is “ideal,” which is something that will vary from user to user anyway.

How many commits of those are just “fixed a few bugs” or “asdfghjkl” or whatever too?

Zero of them.

qsvui
Aug 23, 2003
some crazy thing
i care about line length and definitely am not a nerd

LongSack
Jan 17, 2003

zergstain posted:

Why 72? I thought 80 was the width of those dumb terminals from the 1970s.

Back when I was doing COBOL and FORTRAN on punched cards (yes, I am that old), the rightmost eight columns were reserved for sequence numbers, which you definitely wanted in case you ever dropped a box of cards.

Tei
Feb 19, 2011
Probation
Can't post for 7 days!

LongSack posted:

Back when I was doing COBOL and FORTRAN on punched cards (yes, I am that old), the rightmost eight columns were reserved for sequence numbers, which you definitely wanted in case you ever dropped a box of cards.

wow, you must be really old

I am old, today I mentioned in the 80s in front of some juniors devs, but I realized too late that they never experienced it, except maybe in pop culture.

people tell me the 80s where horrible, and I don't doubt it, but for me it was the 90's that ruined everything.

Us programmers must bring back some customs. For once infinite paper printers to put code into paper. .. or whatever was called these printers that printed using paper forming a single roll of pages connected in the borders forming a zig zag.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Tei posted:

wow, you must be really old

I am old, today I mentioned in the 80s in front of some juniors devs, but I realized too late that they never experienced it, except maybe in pop culture.

people tell me the 80s where horrible, and I don't doubt it, but for me it was the 90's that ruined everything.

Us programmers must bring back some customs. For once infinite paper printers to put code into paper. .. or whatever was called these printers that printed using paper forming a single roll of pages connected in the borders forming a zig zag.

Why are you printing out many many pages of code?

The Fool
Oct 16, 2003


Tei posted:

Us programmers must bring back some customs. For once infinite paper printers to put code into paper. .. or whatever was called these printers that printed using paper forming a single roll of pages connected in the borders forming a zig zag.

Continuous feed printer

more falafel please
Feb 26, 2005

forums poster

a hot gujju bhabhi posted:

Why are you printing out many many pages of code?

In the late 90s/early 200s when I was in junior high/high school I printed out pages upon pages of Z80 assembly code for TI-82 games, so I could read it when I wasn't at a computer. I would write code on paper too.

The Fool
Oct 16, 2003


more falafel please posted:

In the late 90s/early 200s when I was in junior high/high school I printed out pages upon pages of Z80 assembly code for TI-82 games, so I could read it when I wasn't at a computer. I would write code on paper too.

This but tibasic

Only game I’ve ever “published”

Kazinsal
Dec 13, 2011

Tei posted:

Us programmers must bring back some customs. For once infinite paper printers to put code into paper. .. or whatever was called these printers that printed using paper forming a single roll of pages connected in the borders forming a zig zag.

Hell yeah, I'm on board with bringing back dot matrix printers and continuous form paper.

Soricidus
Oct 21, 2010
freedom-hating statist shill

a hot gujju bhabhi posted:

Why are you printing out many many pages of code?

are you really going to read it on a cramped fuzzy little terminal screen, with those cathode rays probably giving you eye cancer? or do you just never do code review?

Qwertycoatl
Dec 31, 2008

https://twitter.com/jfbastien/status/1280709082626666498

more falafel please
Feb 26, 2005

forums poster


It's "could be called" right? There's multiple reasons why malloc() could return nullptr, for one thing, and func(p) may call free(p). With sz staying the same, it's entirely possible that malloc() would return the same pointer that was just freed.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Isn't invoking pointer provenance overcomplicating things there? A simplified version of that code is fairly obviously UB:

code:
void* p = malloc(sz);
free(p);
// p is now indeterminate
void* q = malloc(sz);
// reading an indeterminate value, so UB
if (p == q) {
  call(p);
}
Doing the comparison via uintptr_t is still using the value of a pointer after free, so it's still UB. Therefore the compiler can assume func() does not free p, and therefore q != p.

more falafel please
Feb 26, 2005

forums poster

Plorkyeran posted:

Isn't invoking pointer provenance overcomplicating things there? A simplified version of that code is fairly obviously UB:

code:
void* p = malloc(sz);
free(p);
// p is now indeterminate
void* q = malloc(sz);
// reading an indeterminate value, so UB
if (p == q) {
  call(p);
}
Doing the comparison via uintptr_t is still using the value of a pointer after free, so it's still UB. Therefore the compiler can assume func() does not free p, and therefore q != p.

I guess comparing a pointer (the address itself) is use-after-free? That seems weird, but ok.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

more falafel please posted:

I guess comparing a pointer (the address itself) is use-after-free? That seems weird, but ok.

Yes, in the C abstract machine a pointer points to an object which has an address, and not to an address. Once the object is gone, trying to read the object's address is a use-after-free.

Wait, I guess I said it was pointless to invoke pointer provenance and then went on to describe pointer provenance.

Xarn
Jun 26, 2015

Plorkyeran posted:

Wait, I guess I said it was pointless to invoke pointer provenance and then went on to describe pointer provenance.

:hmmyes:

The better question here is, what is the provenance of a malloc-returned nullpointer? If it is universal, then the last call could be called, if malloc fails both times. If every call to malloc has unique provenance (IIRC Clang believes this), even for nullptrs, then it can never be called.

Xarn fucked around with this message at 23:04 on Jul 8, 2020

Foxfire_
Nov 8, 2010

The clang justification for that optimization is some amusing pedantry.

- When compiled without ffreestanding, clang knows what malloc() does.
- Specifically, it knows that that its specification does not require any visible side-effects
- It is therefore permissible to swap in a different malloc()/free() implementation for that one pair.
- If it can prove you never access through the returned pointer, the new implementation never actually needs to allocate memory
- New implementation never fails on any size allocation so it never returns NULL

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Soricidus posted:

are you really going to read it on a cramped fuzzy little terminal screen, with those cathode rays probably giving you eye cancer? or do you just never do code review?

He said he wants to bring it back, which implies he wants to print out many pages of code today. If he's using a fuzzy little terminal screen today then I guess I get it.

zergstain
Dec 15, 2005

Aren't you, by casting to uintptr_t, saying treat this as an unsigned integer, which would avoid UB in that case?

I really had no idea simply looking at the value of an invalid pointer was UB, I thought you'd have to dereference it. Shows how much I know about C.

Edit: Actually the value is copied to ip before func() is called, and ip is just an unsigned integer with the same width as a pointer on the target platform.

zergstain fucked around with this message at 01:21 on Jul 9, 2020

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
So if I do

void* p = malloc(sz);
uintptr_t ip = (uintptr_t)p;
free(p);

Now both p and ip have indeterminate values?

How about if I itoa ip before freeing the pointer, does the string end up with an indeterminate value?

xtal
Jan 9, 2011

by Fluffdaddy
UB begets UB, like the fruit of a poisonous tree

raminasi
Jan 25, 2005

a last drink with no ice

Jabor posted:

So if I do

void* p = malloc(sz);
uintptr_t ip = (uintptr_t)p;
free(p);

Now both p and ip have indeterminate values?

How about if I itoa ip before freeing the pointer, does the string end up with an indeterminate value?

My understanding is that UB isn't a per-line or per-variable or per-function thing. Once your program has any UB, the entire program's behavior is undefined.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If I don't actually do anything with p after freeing it, then p is not causing the program as a whole to exhibit UB.

Is it UB if I do something with ip after freeing p? What about if I do something with the string I created using atoi while it was still valid?

Foxfire_
Nov 8, 2010

That code seems fine to me. The integer is not a pointer.

Original tweet is 'could be called' because there is no guarantee that the two calls return different values.

code:
void Foo()
{
   void* a = malloc(10000000);
   void* b = malloc(10000000);

    uintptr_t a_num = (uintptr_t)a;
    uintptr_t b_num = (uintptr_t)b;

    free(a);
    free(b)
    
    // a&b are dead, a_num & b_num are not
    
    // These ones are UB though
    // uintptr_t bad = (uintptr_t)a;

    if (a == b)
    {
         printf("dickbutt");
    }
}
is still permissibly optimized into a no-op though.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
There is a class of optimizations with the following form. There is an object: perhaps you've allocated it with malloc, or perhaps it's a local or global variable. The compiler can see all the ways in which you use that object. If those uses look like [insert condition here], the compiler can [insert optimization here].

This is an extremely important class of optimizations. Without it, you can't even turn int x = 5; foo(); bar(x); into foo(); bar(5);. If you cannot do these optimizations, the compiler can do almost nothing with your code once it involves memory of any kind.

These optimizations all assume that you cannot just "guess" a pointer. This is tricky, because of course you can just "guess" a pointer. A pointer has a fixed-size representation in memory, and you can just plop down random bits into that representation and have a 1/N chance of ending up with the right value. More plausibly, you might have some clever way to figure out what the address of an object must be without just copying the pointer. For example, you could figure out the size of a stack frame and then prove that other objects occupy all the other memory. Or you could do a careful series of pointer comparisons to extract the bits of the pointer one by one. Or you could just know that the object has address 0x10107ffe6 in the current build. The point is that the compiler must have some way to say that you aren't allowed to have done that even if you show up with an address that, sure enough, happens to coincide with an object of the right type, because otherwise the compiler might as well be a macro assembler.

(Interestingly, there is a hardware proposal called CHERI in which the actual representation of pointers is special beyond what's expressible in that ordinary memory. It is extremely problematic. But it would potentially change the game here if anyone ever adopted it.)

This is what provenance is about. The idea is that if you take a pointer to an object that happens be at address 0x10107ffe6 and you cast it to an integer and you cast it back, that is fundamentally different from getting a packet from the gods containing the string "0x10107ffe6" and parsing out that integer value and casting to pointer type. That has to be the idea. It is the only way anything works.

xtal
Jan 9, 2011

by Fluffdaddy

Jabor posted:

If I don't actually do anything with p after freeing it, then p is not causing the program as a whole to exhibit UB.

Is it UB if I do something with ip after freeing p? What about if I do something with the string I created using atoi while it was still valid?

Strictly UB yes, not because it's guaranteed to compile or not, but just undefined. Imagine if you were reading bytes from urandom instead of memory addresses. Depending on the way you use them the program may still work, but converting random bytes to a string doesn't make them more meaningful, they're still opaque to you.

edit: efb but also glad someone else compared to randomness

Adbot
ADBOT LOVES YOU

Foxfire_
Nov 8, 2010

xtal posted:

Strictly UB yes, not because it's guaranteed to compile or not, but just undefined. Imagine if you were reading bytes from urandom instead of memory addresses. Depending on the way you use them the program may still work, but converting random bytes to a string doesn't make them more meaningful, they're still opaque to you.

edit: efb but also glad someone else compared to randomness

The program has some unpredictable output. It does not have undefined behavior.

code:
#include <cstdio>
#include <cstdin>

int main()
{
    void* foo = malloc(4);
    uintptr_t bar = (uintptr_t)foo;
    free(foo);

    printf("The pointer was %d\n", (int)bar);
    return 0;
}
is a well defined program. It will print something of form 'The pointer was <some number>\n' then terminate with exit code 0.

An undefined behavior program might:
- Also print that
- Crash
- Print nothing
- Infinite loop
- Return some other exit code
etc...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply